Search code examples
javaandroidkotlinandroid-actionbarrippledrawable

Android action bar options menu item custom selectable background


I'm trying to use the default android action bar with a custom view:

<style name="ActionBar" parent="android:Widget.Material.ActionBar.Solid">
    <item name="android:displayOptions">showCustom</item>
    <item name="android:customNavigationLayout">@layout/customNavigationLayout</item>
</style>

The options menu contains a single item which should always show with text:

<item
    android:id="@+id/action_cancel"
    android:showAsAction="always|withText"
    android:title="@string/action_cancel" />

Now I'm having the issue with the selectable background, which is still the size of an action icon:

How it looks like

How can I setup the action bar to apply a selectable background which fills the whole box of the item?

How it should look like


Solution

  • You can try setting the android:actionBarItemBackground attribute in styles, like so:

    <style name="AppTheme" parent="android:Theme.Material">
        ...
        <item name="android:actionBarItemBackground">?android:selectableItemBackground</item>
    </style>