我之前将窗口背景的颜色设置为白色,现在我尝试将操作栏的颜色更改为绿色。这是我的xml代码:
<style name = "CustomAppTheme2" parent = "android:Widget.Holo.Light">
<item name="android:windowBackground">@color/white</item>
<item name="android:background">@color/green</item>
<item name="android:icon">@android:color/transparent</item>
</style>
问题是使用android:background更改操作栏的颜色,它会溢出并将整个屏幕的颜色更改为绿色。我想要一个清晰的绿色动作栏和它下面的白色窗口。提前谢谢!
答案 0 :(得分:1)
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/CustomActionBarTheme">
<!-- Customize your theme here. -->
</style>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/top_bar_blue</item>
<!-- Support library compatibility -->
<item name="background">@drawable/top_bar_blue</item>
<item name="titleTextStyle">@style/myTheme.ActionBar.Text</item>
</style>
<!-- ActionBar Text -->
<style name="myTheme.ActionBar.Text" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">20sp</item>
<item name="android:textStyle">bold</item>
<item name="android:fontFamily">sans-serif-bold</item>
</style>
<!-- In Manifest -->
android:theme="@style/AppTheme"
答案 1 :(得分:1)
您可以从其中一个类扩展ActionBarActivity
并执行以下操作:
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
//Change the color of the actionbar by changing the value in the next line
actionBar.setBackgroundDrawable(new ColorDrawable(#FFFFFF));