Appcompat工具栏列表项背景颜色

时间:2017-12-24 11:27:40

标签: android toolbar android-styles android-menu

我可以根据要求成功地将弹出菜单的背景颜色更改为白色,但列表项不会跟随。我使用此代码:

<style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:background">@color/colorToolbar</item> <!-- green -->
    <item name="android:textColorPrimary">@color/white</item>
    <item name="android:itemBackground">@color/white</item>
</style>

并使用app:theme直接将其传递给工具栏。

不幸的是,这就是发生的事情:

enter image description here

如何将列表项设为白色,文本颜色为黑色?

1 个答案:

答案 0 :(得分:0)

您可以使用app:popupTheme更改列表项的颜色。

工具栏布局:

<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/AppTheme.ToolbarOverlay"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

主题:

<style name="AppTheme.ToolbarOverlay" parent="ThemeOverlay.AppCompat.Dark">
    <item name="colorPrimary">@android:color/holo_green_dark</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

结果:

Green toolbar with list with white background and black text

相关问题