簡體   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