The position name does not appear in the portrait with SHOW_AS_ACTION_WITH_TEXT

In my activity, I have an action mode with a single element that has a title and icon.

I want the title and icon to be displayed, so I use the SHOW_AS_ACTION_WITH_TEXT and SHOW_AS_ACTION_ALWAYS flags.

In landscape orientation, this is beautiful. I have a title + icon. But in portrait orientation only the icon is displayed (although there is a lot of free space). Does anyone know what I can do to fix this?

Please note that the title is displayed correctly if I delete the icon.

Here is my sample code:

public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startActionMode(new Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { menu.add("Item 1").setIcon(R.drawable.ic_launcher).setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT | MenuItem.SHOW_AS_ACTION_ALWAYS); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); } } 
+4
source share
2 answers

Does anyone know what I can do to fix this?

I doubt you can. “Always” and “with text” are requests, not commands. The structure does not always honor them both.

+3
source

Instead of adding this menu item through code, try using this attribute:

 android:showAsAction="always|withText" 

and add it to the item in menu.xml

0
source

Source: https://habr.com/ru/post/1446463/


All Articles