因此,我为应用程序创建了一个主题:
<style name="MainApplicationTheme" parent="@style/Theme.AppCompat">
<item name="android:background">@color/light_green</item>
</style>
现在工具栏具有与主应用程序背景相同的颜色。如何更改工具栏的颜色,而无需为工具栏创建新的布局,也不需要在每个活动中都更改这些代码?
在您要更改工具栏颜色的活动中,可以使用以下命令:
ActionBar actionBar = getSupportActionBar();
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#000000"));
actionBar.setBackgroundDrawable(colorDrawable);
这会将背景色更改为black
。或者,如果您想在主题内对其进行更改,请按照以下步骤操作:
<style name="MainApplicationTheme" parent="@style/Theme.AppCompat">
<item name="android:background">@color/light_green</item>
<item name="actionBarTheme">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/black</item>
</style>
这也会将其更改为黑色。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句