[英]Setting background color of android actionbar
我正在使用兼容性库v7。
我只是想将操作栏的颜色(适用于Android 2.1及更高版本-尽管我运行Android 4.4.2)设置为纯色。
但是颜色不会改变。 它保持不变。
我也尝试过用颜色创建一个可绘制的实体,但是它也不会改变。
最后,我测试了是否可以更改布局的背景,并且可以-它一定是关于我没有得到的操作栏背景的内容。
这是代码:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomActionBarTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">#0000ff</item>
</style>
</resources>
这似乎为我工作。 尝试使用资源而不是原始值。
<style name="app_theme" parent="@android:style/Theme.Holo">
<item name="android:actionBarStyle">@style/app_action_bar</item>
</style>
<style name="app_action_bar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@color/google_lightest_gray</item>
<item name="android:icon">@android:color/transparent</item>
<item name="android:windowActionBarOverlay">false</item>
</style>
使用getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#808080")));
在Activity extends SherlockActivity
或根据需要选择颜色:)
您可以使用:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.colorname));
使用以下代码getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg_color.xml));
actionbar_bg_color.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/actionbar_bg"/> <!-- set desired #0000ff color in color.xml
you can use here solid color as well as gradient -->
</shape>
希望这对你有帮助
我通过以下方法解决了它:
我不知道为什么不能在themes.xml中得到想要的结果。
如果有人有答案,我将不胜感激
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.