Fit Toolbar title

2019-08-17 08:10发布

I have the following issue with my app, specifically with the Action Bar:

enter image description here

and the ID (indicated with the red rectangle) but since the size of the Action Bar nor the icons contained in cannot be changed due to esthetic reasons, I would like to display a text with the whole number and ID when the users press in the section I've highlighted.

Currently, I'm setting the text like this(delivery var and idDelivery are Strings):

    ActionBar ab = getActionBar();
    ab.setTitle(delivery);
    ab.setSubtitle("ID:" + idDelivery);

Any ideas?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-17 08:36

Change MenuItems showAsAction attribute to ifRoom:

<item app:showAsAction="ifRoom"
        .../>

From docs:

Only place this item in the app bar if there is room for it. If there is not room for all the items marked "ifRoom", the items with the lowest orderInCategory values are displayed as actions, and the remaining items are displayed in the overflow menu.

Thus, the title of your Toolbar would be given higher priority, and MenuItems would be displayed only when there is enough room for them, otherwise they would be left to be displayed under overflow icon popup menu.

查看更多
登录 后发表回答