Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 399
tynn Avatar asked Aug 18 '19 17:08

tynn


People also ask

How to create Android option menus and backgrounds?

Android Option Menus are the primary menus of the activity. They can be used for settings, search, delete items, etc. We will first create vector assets for the icon. Then we will set the icon in the toolbar items. Similarly, for the background, we will first create a custom style for the toolbar.

What is options menu in Android app?

Options menu and app bar. The options menu is the primary collection of menu items for an activity. It's where you should place actions that have a global impact on the app, such as "Search," "Compose email," and "Settings.".

How do I add an icon to an Android Actionbar?

android:icon: The icon of an item is referenced in the drawable directories through this attribute. Icon of an ActionBar Item In order to provide an icon to an item, right-click on the res folder, select new, and then Image Asset. A dialog box will appear, choose the Icon Type as Action Bar and Tab Icons.

What is the default Actionbar in Android?

All applications that use the default theme provided by the Android (Theme.AppCompat.Light.DarkActionBar), contains an ActionBar by default. However, developers can customize it in several ways depending upon their needs.


Video Answer


1 Answers

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>
like image 104
Jalvap Avatar answered Oct 21 '22 03:10

Jalvap