Android 安卓-更改栏颜色显示默认主题

Android 安卓-更改栏颜色显示默认主题,android,colors,Android,Colors,我想在不更改主题或样式的其他属性的情况下,更改应用程序所有视图的操作栏的背景色 有没有办法通过xml资源来实现这一点 感谢降低API级别,请检查 对于大于或等于11的API级别 检查应用程序的版本,并更改API级别>11的ActionBar的颜色 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { // only for HoneyComb and

我想在不更改主题或样式的其他属性的情况下,更改应用程序所有视图的操作栏的背景色

有没有办法通过xml资源来实现这一点


感谢降低API级别,请检查

对于大于或等于11的API级别

检查应用程序的版本,并更改API级别>11的ActionBar的颜色

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
             // only for HoneyComb and newer versions
            ActionBar bar = getActionBar();

            // title;
            bar.setTitle(Html.fromHtml("<font color='#000000'>APP</font>"));

            //Rgb for yellow.
            bar.setBackgroundDrawable(new ColorDrawable(Color.rgb(255,215,0)));
        }

是的,你可以。您必须使用styles.xml文件。不仅是颜色,你甚至可以提供自己的背景画

使用下面的方法。 @样式/MyActionBar

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>    </style>

<!-- general styles for the action bar -->
<style name="MyActionBar"
       parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">#f00</item> oR
    <item name="android:background">@drawable/actionbar_background</item>

    <!-- Support library compatibility -->
    <item name="background">#F00</item> oR
    <item name="background">@drawable/actionbar_background</item>
</style>

有关更多样式,请参阅。

很抱歉,这是针对支持库的。使用下面的方法

<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
       parent="@style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">#fff</item>
</style>

请在colors.xml中添加颜色代码,然后在此处引用:检索项的父项时出错:未找到与给定名称“@style/Widget.AppCompat.ActionBar”匹配的资源。请参见上文,我已添加了该代码段。这里是开发人员页面,用于设计ActionBar的样式,我希望通过xml来实现。谢谢。@user2655890我的回答帮助了你: