Skip to content Skip to sidebar Skip to footer

WithText In Split ActionBar

I'm having an issue where if the ActionItem has both an icon and text and the ActionBar is split, it will only show the icon even if the showAsAction='always|withText'. Is there a

Solution 1:

withText is a hint to the system. On width-constrained devices or configurations the system may choose to ignore it.


Solution 2:

I had the same problem recently and as already answered by adamp, there is no way to force the text to appear with the "withText" option.

Actually this can be done with a custom view in the Actionbar as i.e. in The Google Calendar's Edit/Create Event Screen (Cancel and Save button in the action bar, both with text).

Check the Google Calendars source on how it is done

https://android.googlesource.com/platform/packages/apps/Calendar

there is a layout for the Actionbar custom View in

res/layout/edit_event_custom_actionbar.xml

please also check the related styles

this is applied to the Actionbar in the EditEventFragment class, method onCreateView

if (mUseCustomActionBar) {
     View actionBarButtons = inflater.inflate(R.layout.edit_event_custom_actionbar,
             new LinearLayout(mContext), false);
     View cancelActionView = actionBarButtons.findViewById(R.id.action_cancel);
     cancelActionView.setOnClickListener(mActionBarListener);
     View doneActionView = actionBarButtons.findViewById(R.id.action_done);
     doneActionView.setOnClickListener(mActionBarListener);

     mContext.getActionBar().setCustomView(actionBarButtons);
 }

The event handlers are assigned there as well.

The Actionbar display option are set in the EditEventActivity class, onCreate method:

getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,                      
         ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME|
         ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);

This is what I figured out so far. There is some additional configuration for other screen options (tablets) using the standard menu configuration for the actionbar, but using a similar layout, style and those two snippets in my own code, produced the expected result (actionbar item with text).

Hope this helps


Post a Comment for "WithText In Split ActionBar"