在安卓工作室中,我正在使用AppCompat api28,如何在样式.xml文件中更改工具栏属性,如背景颜色等



>我已经尝试了很多选项,但无论我使用什么,似乎我都无法更改"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>

在清单中,我使用"自定义操作栏主题"作为我的默认主题。

我找到了解决方案,我的第一个错误是我应该使用这样的主题:"Theme.AppCompat.Light",任何以主题开头的东西,最后创建一个像波纹管这样的样式,父设置为"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>

您可以在下面找到操作栏的所有其他属性:https://developer.android.com/reference/android/R.styleable.html#ActionBar

最新更新