自定义主题在FragmentActivity不适用 [英] Custom Theme not applying in FragmentActivity

查看:317
本文介绍了自定义主题在FragmentActivity不适用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主题不工作我已经看到了这一点<一个href=\"http://stackoverflow.com/questions/8024706/how-do-i-change-the-background-color-of-the-actionbar-of-an-actionbaractivity-us/27847656#27847656\">How做我使用XML改变ActionBarActivity的动作条的背景颜色?但不工作
仍然只有灰色活动SplahScreen改变,但 MainActivity 不能延长FragmentActivity:
清单:

My theme is not working I have seen this How do I change the background color of the ActionBar of an ActionBarActivity using XML? but not working still grey only SplahScreen activity changed but MainActivity extend FragmentActivity not: Manifest:

   <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

I have localization and add theme file in every Language also in value-11 still not changed: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尝试(新ColorDrawable(COLOR));

Tried with getActionbar.setBackgroundDrawable(new ColorDrawable("COLOR"));

请看看我的项目结构:再闪屏的活动主要活动包括至极,在activitis彩色背景片段导航抽屉改变,但不是在片段

please look my project structure:splash screen activity then Main activity wich include navigation drawer with fragments in activitis color background changed but not in the fragment

推荐答案

您也不能因为您没有使用改变动作条背景颜色 Widget.Holo.Light.ActionBar.Solid.Inverse MyActionBar

You could not be able to change the actionbar background color because you are not using Widget.Holo.Light.ActionBar.Solid.Inverse as the parent of 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>

来源:自定义背景ActiobBar(官方文档)

这篇关于自定义主题在FragmentActivity不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆