Search code examples
androidcontextual-action-barandroid-actionmode

Remove Title from Contextual Action Bar


I want to remove the view that is allocated for the title in a contextual action bar.

This is what I want to remove

Please note that I do not want to set the title; I want the View entirely gone. This is to allow more room so that actions can be displayed on the menu bar rather than being dropped into the overflow menu.

Also note that I do not want to set android:showAsAction="always". I want Android to decide how much space there is for the icons. I just want there to be more space by removing the blank area that is reserved for a title.

UPDATE

Things I have tried:

  • ActionMode.setCustomView(null)
  • ActionMode.setTitleOptionalHint(true)
  • ActionMode.setTitle("").

Unfortunately, none of these have worked.


UPDATE 2

It turns out my desired results are impossible to achieve in the way I was attempting. Removing the title will not allow room for more icons; Android sets a hard limit based upon the device screen size. If you are wanting to add more icons to the menu, see the answer provided by @adneal.

If you actually have a title (as shown below) and want to remove it, then you can call ActionMode.setTitle(""), as provided by @CommonsWare in the accepted answer.

Example of a menu with a title


Solution

  • Try calling setCustomView(null) on the ActionMode.

    If that does not work, try setTitleOptionalHint(true) on the ActionMode.

    If that does not work, try setTitle("") on the ActionMode.