문제

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 way to force the text to appear?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top