【问题标题】:After applying custom theme Action bar dosen't show up应用自定义主题后,操作栏不显示
【发布时间】:2013-11-06 04:49:37
【问题描述】:

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

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 并显示操作栏,但是当我使用 parent 作为 Theme.Light 自定义主题时,它不起作用但如果我使用 parent 作为 Theme.Holo 那么它适用于自定义主题。任何人任何想法。

【问题讨论】:

    标签: android styles android-actionbar themes


    【解决方案1】:

    这就是我所做的。它对我来说非常有效。在 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 是我使用的背景颜色。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多