我尝试了很多选项,但无论我使用什么,似乎我无法更改'style.xml'文件中的工具栏或操作栏颜色和样式。似乎使用'android.support.v7.widget.toolbar'是我唯一的选择。你知道一种方法,以便我可以在'style.xml'文件中更改操作栏样式吗?
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="android:background">#ff0000</item>
</style>
在清单中我使用'CustomActionBarTheme'作为我的默认主题。
我找到了解决方案,我的第一个错误是我应该使用像'Theme.AppCompat.Light'这样的主题,任何以Theme开头的东西,最后创建一个像bellow一样的样式,父级设置为'Widget.AppCompat.ActionBar'
<style name="customActionbarStyle" parent="Widget.AppCompat.ActionBar">
<item name="background">@color/your_custom_color</item>
// also notice you must use color.xml file for colors and for some attributes
// like titleTextStyle , you must define another style and use it here like :
<item name="titleTextStyle">@style/your_title_text_style</item>
</style>
<style name="your_title_text_style">
<item name="android:textColor">@color/your_text_color</item>
</style>
你可以找到ActionBar的所有其他属性:https://developer.android.com/reference/android/R.styleable.html#ActionBar