Solution to the problem that menu in toolbar cannot display icon and text at the same time

When using the toolbar, although the icon attribute is set in the item of the menu.xml file, when showasaction = "never" is set, only the title of the text is displayed by default, not the icon icon. You can override the onmenuopened () method in the activity to make the icon and title visible at the same time through reflection.

Copy the following code into the activity:

The effects before treatment are as follows:

Override onmenu opened(), and the effect after processing is as follows:

You can see that both icons and text are displayed at the same time.

My menu.xml file is as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>