我想用十六进制颜色代码更改操作栏的颜色。请帮助我逐步修改操作栏的颜色。我是Android的新手。请告诉我所有步骤以及更改颜色的解释。
答案 0 :(得分:2)
您可以在style.xml文件中定义自己的样式
<resources>
...
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">HEX_COLOR_CODE</item>
</style>
...
</resources>
但它只能从11级API开始工作。此外,您可以使用工具栏并为其设置背景。
或者,如果您想在代码中更改它
ActionBar actionBar = getActionBar(); //for app compat - call getSupportActionBar()
actionBar.setHomeButtonEnabled(true);
ColorDrawable colorDrawable = new ColorDrawable(
Color.parseColor("#0086D4"));
actionBar.setBackgroundDrawable(colorDrawable);