繁体   English   中英

应用自定义主题后,操作栏不会显示

[英]After applying custom theme Action bar dosen't show up

我有一个使用操作栏的应用程序

styles.xml

    <resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <color name="custom_theme_color">#ffa900</color>

    <style name="CustomTheme" parent="android:Theme.Light">
        <item name="android:windowBackground">@color/custom_theme_color</item>
        <item name="android:colorBackground">@color/custom_theme_color</item>
    </style>

</resources>

表现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.actionbar"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" >
        <activity
            android:name="com.example.actionbar.ActionBarActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我的问题是,默认情况下最初使用的是Theme.Light和操作栏,但是当我使用父级作为Theme.Light自定义主题时,它不起作用,但是如果我将parent用作Theme.Holo,则它适用于自定义主题。 任何人任何想法。

这是我所做的。 它对我来说非常有效。 在Res-> value-> style中

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomTheme"
       parent="@style/Theme.Light">       

       <item android:name="actionBarStyle">@style/MyActionBar</item>

</style>
<!-- ActionBar styles -->
<style android:name="MyActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
              <item android:name="background">@drawable/actionbar_background</item> 
</style>
</resources>

然后在drawable文件夹中(如果没有则创建一个),创建一个新的xml actionbar_background并将以下代码粘贴到其中。

 <?xml version="1.0" encoding="utf-8"?>
  <bitmap android:tileMode="repeat" 
    android:src="@drawable/ab_texture_tile_example" 
   xmlns:android="http://schemas.android.com/apk/res/android"/>   

然后,将自定义颜色放置在其他可绘制文件夹中。 这里ab_texture_title_example是我使用的背景色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM