【问题标题】:Android ActionBar color change from manifest not behaving properlyAndroid ActionBar 颜色从清单更改不正常
【发布时间】:2014-01-28 07:04:44
【问题描述】:

我正在通过创建自己的样式并通过清单应用来更改 Android ActionBar 颜色。但是当我在模拟器上运行时,ActionBar 以及屏幕本身正在改变颜色。看图:

我试图搜索这个问题的答案,但没有得到解决。这是清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.actionbartestapp"
    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/MyActionBar" >
        <activity
            android:name="com.example.actionbartestapp.MainActivity"
            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>

这是 Styles.xml 文件:

<resources>

    <!--
        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>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@color/SmugeBlue</item>
    </style>

</resources>

【问题讨论】:

  • 使用 ​​@drawable/actionstyle 在 "actionstyle" 里面放上你需要的纯色

标签: android android-actionbar android-manifest android-styles


【解决方案1】:

在你的代码中

  parent="android:Theme.Light

注意我的代码的变化

  parent="@android:style/Theme.Holo.Light"

另请注意&lt;item name="android:actionBarStyle"

  <item name="android:actionBarStyle">@style/MyActionBar</item> // for action bar only

你有

  <item name="android:background">@color/SmugeBlue</item> // so it changes background for entire screen

在相应的 res/values/styles.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">#FF9D21</item> // change to blue color
  </style> 

在清单中

   android:theme="@style/MyTheme"

您可以看到一个带有快照的示例,尽管回答了有关溢出菜单图标的问题,但它确实表明操作栏颜色已更改

Change action bar overflow icon

更多样式

https://developer.android.com/training/basics/actionbar/styling.html

【讨论】:

  • Raghu,再次指出您应该详细说明 OP 的问题/问题中的错误部分以及您建议的解决方案是什么!
  • @Raghunandan 你检查过你是如何直接将颜色代码放入样式中的吗?你需要在drawable中给出颜色代码。它有效吗?
  • @appubala 你可以使用 colors.xml 并提供他们的颜色代码
  • @appubala 是的,这是我帖子中发布的内容
  • 现在看来,完美答案 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-12
  • 1970-01-01
  • 2015-07-25
相关资源
最近更新 更多