【问题标题】:Custom Theme not applying in FragmentActivity自定义主题不适用于 FragmentActivity
【发布时间】:2015-04-20 23:01:09
【问题描述】:

我的主题不工作我看到这个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("COLOR"));

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

【问题讨论】:

  • actionBar.setBackgroundDrawable(new ColorDrawable(Color .parseColor("#ffdddf"))); //试试这个
  • @Surender Kumar 在 MainActivity 中没有工作仍然是灰色的
  • 你是否从清单中删除了 android:theme=""??
  • 你使用的是Light.ActionBar,但是背景设置为深色,为什么不直接使用DarkActionBar
  • @Xingchen 用于测试

标签: android


【解决方案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)

【讨论】:

  • 仍然有问题,所有活动操作栏都发生了变化,但主活动没有变化,可能是因为主活动中的 FragmentActivity 仅更改了文本颜色并且仍然是灰色
  • 我正在使用支持库
  • @Sultan 您是否在操作栏主题中包含了支持库的 xml 代码?你在说什么文字颜色?
  • 操作栏的文本颜色变为白色,其他活动(如正确颜色的闪屏但不是 MainActivity),如何包含:我正在使用 import android.support.v4.app.ActionBarDrawerToggle;导入android.support.v4.app.Fragment;导入android.support.v4.app.FragmentActivity;导入 android.support.v4.app.FragmentManager;导入 android.support.v4.widget.DrawerLayout;
  • 你的意思是 @style/MyActionBar 是的,我包括
猜你喜欢
  • 2021-01-29
  • 2020-06-09
  • 1970-01-01
  • 2019-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-05
  • 2017-05-11
相关资源
最近更新 更多