rahul.taicho
rahul.taicho

Reputation: 1379

ActionMode menu not hiding menu item

I'm using an action mode with my list view for multi-select. The problem I'm having is that the icon I've specified as hidden in my action mode's menu is never hidden in an overflow menu when testing on emulator, although in the preview it is. I'm using AppCompat theme here is my menu.xml --->

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/tag"
        android:enabled="true"
        android:title="Tag"
        android:icon="@drawable/in_ic_tag_white_24dp"
        android:orderInCategory="1"
        app:showAsAction="always" />

    <item
        android:id="@+id/delete"
        android:enabled="true"
        android:title="@string/label_delete"
        android:icon="@drawable/in_ic_delete_white_24dp"
        android:orderInCategory="2"
        app:showAsAction="never" />

</menu>

Upvotes: 2

Views: 1197

Answers (2)

Sam Chen
Sam Chen

Reputation: 8867

When using Action Mode, the app:showAsAction="never" doesn't work:

change: app:showAsAction="never"

to: android:showAsAction="never"


Or use this line of code:

menu.findItem(R.id.XXX).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

Upvotes: 6

rubengees
rubengees

Reputation: 1860

If I get your question right, you try to hide your MenuItem with showAsAction. "Never" means in this case that it will just not shown as a icon, but it is in the overflow menu.

Maybe you are looking for visibility. For example:

android:visible="false"

Documentation for the programmatically approach: http://developer.android.com/reference/android/view/MenuItem.html#setVisible(boolean)

Upvotes: 0

Related Questions