如何获得自定义工具栏上菜单项的涟漪效果? [英] How do I get the ripple effect for menu items on my custom toolbar?

查看:21
本文介绍了如何获得自定义工具栏上菜单项的涟漪效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a toolbar with the following layout

<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>

现在在棒棒糖之前的设备上,菜单项的可选背景工作得很好,但在棒棒糖上,点击这些项目没有背景.我需要添加什么才能获得棒棒糖的涟漪效果?

Now on pre-lollipop devices the selectable background for the menu items works just fine but on lollipop there's no background for tapping those items. What do I need to add to get the ripple effect for lollipop?

推荐答案

好的,对于任何有兴趣的人,我都想通了.您需要在values-v21"文件夹中为工具栏定义单独的样式,然后向其中添加以下项目:

OK so for anyone interested I figured it out. You need to define a separate style for your toolbar in the 'values-v21' folder then add the following items to it:

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

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

By the way, my AppTheme inherits from Theme.AppCompat.Light.NoActionBar

这篇关于如何获得自定义工具栏上菜单项的涟漪效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆