如何在自定义工具栏上为菜单项添加涟漪效果?

9

我有一个以下布局的工具栏

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/primary_dark"
    android:theme="@style/ToolbarTheme"/>

我正在使用的主题

<style name="ToolbarTheme" parent="AppTheme">
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:popupBackground">@color/white</item>
        <item name="android:textColor">@color/black</item>
        <item name="actionMenuTextColor">@color/black</item>
        <item name="android:textColorSecondary">@color/white</item>
    </style>

现在,在Android 5.0以下的设备上,菜单项的可选背景运行得很好。但是在Android 5.0及以上版本中,点击这些选项时没有背景效果。我需要添加什么内容才能在Android 5.0及以上版本中获得涟漪效果?


什么是涟漪效应? - Buddy
1
https://www.youtube.com/watch?v=J8HF-A-VnMM - ubercharge_ready
1个回答

12

好的,对于任何有兴趣的人,我已经解决了。您需要在“values-v21”文件夹中为您的工具栏定义单独的样式,然后将以下项目添加到其中:

<item name="selectableItemBackground">?android:selectableItemBackground</item>
<item name="android:colorControlHighlight">@color/ripple_material_dark</item>

顺便提一下,我的AppTheme继承自Theme.AppCompat.Light.NoActionBar


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接