我在Manifest文件中包含了我的主题。我的主题代码如下
<resources>
<!-- Activity themes -->
<style name="Theme.Base" parent="Theme.AppCompat.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<style name="AppTheme" parent="Theme.Sample" >
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/blue</item>
</style>
</resources>
我的所有活动都会继承ActionBarActivity
我似乎无法改变ActionBar
的颜色。
请帮忙。
我在使用API 21的模拟器上运行它。
如何设置ActionBar的样式?
答案 0 :(得分:1)
AppCompat v21不会读取与操作栏相关的任何android:属性:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Here we setting appcompat’s actionBarStyle -->
<item name="actionBarStyle">@style/MyActionBarStyle</item>
<!-- ...and here we setting appcompat’s color theming attrs -->
<item name="colorPrimary">@color/my_awesome_red</item>
<item name="colorPrimaryDark">@color/my_awesome_darker_red</item>
<!-- The rest of your attributes -->
</style>
答案 1 :(得分:0)
您可以更改将此代码添加到您的样式的颜色:
<item name="colorPrimary">@android:color/holo_red_dark</item>
使用colorPrimaryDark,您可以更改状态栏颜色。
小心,使用colorPrimary,不要使用android:colorPrimary,这最后只适用于21。
所有代码:
<resources>
<!-- Activity themes -->
<style name="Theme.Base" parent="Theme.AppCompat.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<style name="AppTheme" parent="Theme.Sample" >
<item name="colorPrimary">@android:color/holo_red_dark</item>
</style>
</resources>
答案 2 :(得分:0)
我发现这个Google Blog Post对于v21 appCompat非常有帮助。它解释了用法非常好。
答案 3 :(得分:-1)
您可以通过以下方式执行此操作
只需编辑Android项目的res / values / styles.xml文件即可。
例如:
<resources>
<style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
或通过java代码
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));