Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the ripple effect for menu items on my custom toolbar?

Tags:

android

xml

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

and the theme I'm using

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

like image 294
ubercharge_ready Avatar asked Aug 20 '15 12:08

ubercharge_ready


1 Answers

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>

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

like image 167
ubercharge_ready Avatar answered Sep 27 '22 20:09

ubercharge_ready