自定义主题不适用于FragmentActivity

时间:2015-02-19 14:39:35

标签: android

我的主题不起作用我看过这个How do I change the background color of the ActionBar of an ActionBarActivity using XML?但没有用 仍为灰色只有SplahScreen活动已更改但MainActivity extend FragmentActivity未更改: 清单:

   <application
     android:largeHeap="true"
    android:name="asasdsd.asdasdas"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher2"
    android:label="@string/app_name"
    android:theme="@style/MyTheme"
   >
    <activity
        android:name="app.sultan.sdcinfo.SplashScreen"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

     <activity
        android:name="app.sultan.sdcinfo.MainActivity"
        android:label="@string/app_name"
                android:theme="@style/MyTheme"
         >
    </activity> 

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

我有本地化并在每个语言中添加主题文件,值仍然没有改变:11:Theme.xml

      `<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
      <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

   <style name="MyActionBar"    parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#262626</item>
  </style>`

尝试使用getActionbar.setBackgroundDrawable(new ColorDrawable(&#34; COLOR&#34;));

请查看我的项目结构:启动屏幕活动然后主要活动包括导航抽屉,活动炎颜色背景中的碎片已更改但未在片段中

1 个答案:

答案 0 :(得分:1)

您无法更改操作栏背景颜色,因为您没有使用Widget.Holo.Light.ActionBar.Solid.Inverse作为MyActionBar的父级

使用

parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"

而不是

parent="@android:style/Widget.Holo.Light.ActionBar

所以你的theme.xml会是,

<resources>
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

   <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
       <item name="android:background">#262626</item>
   </style>
</resources>

来源:Customize ActiobBar Background (Official Documentation)

相关问题