更改android中的操作栏颜色

use*_*569 17 android android-layout

Theme.Black在我的应用程序中使用应用程序主题.在这个主题中,动作栏是灰色的.我如何改变动作栏的颜色?这是我的尝试:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="mytheme" parent="@android:style/Theme.Black" >

    </style>
    <style name="Widget.MyApp.ActionBar" parent="@android:style/Widget.ActionBar">
        <item name="android:background">@android:color/black</item>
    </style>



</resources>
Run Code Online (Sandbox Code Playgroud)

但是,它不起作用.有任何想法吗?

use*_*831 23

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR")); 
Run Code Online (Sandbox Code Playgroud)

它在这里对我 有用

  • 谢谢.它对我有用.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.material_blue_gray1))); (3认同)

zap*_*ech 9

<style name="AppTheme" parent="AppBaseTheme">

    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#C1000E</item>
    <item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.StatusBar.Title">
    <item name="android:textColor">#E5ED0E</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我已经解决了使用它.

  • 我已经厌倦了这个. (3认同)

Luf*_*ffy 7

 ActionBar actionBar;

 actionBar = getActionBar(); 
 ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#93E9FA"));     
 actionBar.setBackgroundDrawable(colorDrawable);
Run Code Online (Sandbox Code Playgroud)

  • `new ColorDrawable(0x93E9FA);` (2认同)

Bru*_*eri 0

也许这也可以帮助你。它来自网站:

\n\n

http://nathanael.hevenet.com/android-dev-changing-the-title-bar-background/

\n\n
\n

首先,您需要为您的应用程序(或活动,取决于您的需要)声明一个自定义主题。类似于\xe2\x80\xa6

\n
\n\n
<!-- Somewhere in AndroidManifest.xml -->\n<application ... android:theme="@style/ThemeSelector">\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

然后,为两种情况声明您的自定义主题,即带有和不带有 Holo 主题的 API 版本。对于旧主题,我们\xe2\x80\x99 将自定义 windowTitleBackgroundStyle 属性,对于新主题,我们将自定义 ActionBarStyle。

\n
\n\n
<!-- res/values/styles.xml -->\n<?xml version="1.0" encoding="utf-8"?>\n<resources>\n\n    <style name="ThemeSelector" parent="android:Theme.Light">\n        <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>\n    </style>\n\n    <style name="WindowTitleBackground">     \n        <item name="android:background">@color/title_background</item>\n    </style>\n\n</resources>\n\n<!-- res/values-v11/styles.xml -->\n<?xml version="1.0" encoding="utf-8"?>\n<resources>\n\n    <style name="ThemeSelector" parent="android:Theme.Holo.Light">\n        <item name="android:actionBarStyle">@style/ActionBar</item>\n    </style>\n\n    <style name="ActionBar" parent="android:style/Widget.Holo.ActionBar">     \n        <item name="android:background">@color/title_background</item>\n    </style>\n\n</resources>\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

那\xe2\x80\x99就是它!

\n
\n