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

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.

Also note that I do not want to set android:showAsAction="always"
You have to if you want more than two action buttons in the ActionBar, at least on smaller screens. The ActionBarPolicy determines how many action button to place in the ActionBar and the default amount is 2.
The only way to override that default value is to make your MenuItem "always" appear.
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.setTitle(null);
for (int i = 0; i < 5; i++) {
menu.add("Item " + (i + 1)).setIcon(android.R.drawable.sym_def_app_icon)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
return true;
}
Results

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With