Android操作栏选项菜单颜色更改

时间:2018-08-14 07:15:32

标签: android android-actionbar

我为我的android应用设置了自定义主题。我必须更改选项菜单颜色,现在是白点。我必须将颜色更改为红色。

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle" tools:targetApi="23">@style/ActionBarStyle</item>
    <item name="android:actionBarTabTextStyle" tools:targetApi="23">@style/ActionBarTabText
    </item>

    <item name="colorControlNormal">@color/vkcred</item>
    <!--<item name="drawerArrowStyle">@style/DrawerIcon</item>-->

    <item name="android:popupBackground" tools:targetApi="23">@color/home_list_color</item>
    <item name="android:actionMenuTextColor" tools:targetApi="23">@color/action_bar_title</item>
    <item name="android:actionBarWidgetTheme">@style/PopupWrapper</item>
    <item name="android:itemTextAppearance">@style/menuCustomMenuTextApearance</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/ActionBarStyle</item>
    <item name="actionBarTabTextStyle">@style/ActionBarTabText</item>

    <item name="actionMenuTextColor">@color/action_bar_title</item>
    <item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
</style>

<style name="Widget.ActionButton.Overflow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
    <item name="android:contentDescription">@string/accessibility_overflow</item>
    <item name="android:dropDownListViewStyle">@style/PopupMenuListView</item>
</style>

<style name="PopupWrapper" parent="@android:style/Theme.Holo">
    <item name="android:popupMenuStyle">@style/PopupMenuStyle</item>
</style>
<!-- ActionBar styles -->
<style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar.Solid">


    <item name="android:titleTextStyle" tools:targetApi="23">@style/ActionBarTitleText</item>
    <!--  <item name="android:background" tools:targetApi="11">@drawable/titlebar</item> -->
    <item name="android:popupBackground" tools:targetApi="23">@color/home_list_color</item>
    <!-- <item name="windowActionBar">false</item>-->
    <!-- Support library compatibility -->
    <item name="titleTextStyle">@style/ActionBarTitleText</item>
    <!--<item name="background">@color/white</item>-->


</style>

<!-- ActionBar title text -->
<style name="ActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/action_bar_title</item>
    <!-- The textColor property is backward compatible with the Support Library -->
</style>

<!-- ActionBar tabs text -->
<style name="ActionBarTabText" parent="@style/Widget.AppCompat.ActionBar.TabText">
    <item name="android:textColor">@color/action_bar_title</item>
    <!-- The textColor property is backward compatible with the Support Library -->
</style>

实际上,我必须将选项菜单颜色更改为红色。由于我不熟悉使用样式进行主题更改,因此无法找到问题所在。嗨,我不是使用工具栏,而是使用getSupportActionBar()。请帮助我解决

3 个答案:

答案 0 :(得分:0)

在style.xml内部,将您的colorPrimary和colorSecondary更改为红色和浅红色,

您可以在https://www.materialpalette.com上找到物料托盘 下载style.xml并粘贴到res文件夹中。

答案 1 :(得分:0)

在您的CustomActionBarTheme中尝试以下代码:

<!-- android:textColorSecondary is the color of the menu overflow icon (three vertical dots) -->
<item name="android:textColorSecondary">@color/red</item>

并将父主题更改为:

<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light">

希望有帮助!

答案 2 :(得分:0)

<style name="MyToolbarTheme">
    <!-- Used to tint the back arrow, menu and spinner arrow -->
    <item name="colorControlNormal">#EF5350</item> //red
</style>

<Toolbar
    android:theme="@style/MyToolbarTheme"
    .../>

您可以通过编程方式设置主题

getSupportActionBar().getThemedContext().setTheme(R.style.MyToolbarTheme);