Menu menu example of Android dynamic modification toolbar

Android dynamically modifies the menu menu of the toolbar

design sketch

realization

The implementation is very simple. It is a menu with three actions. When we slide to different states, we hide the corresponding actions.

Start loading

Menu

Add 3 items under menu

Override the onprepareoptionsmenu method

Used to control the items displayed in the menu according to the viewpager display page

In the demo, I use viewpager sliding to control, which can be based on my own needs, but most of them judge viewpager.

Item Click

Listen to the viewpager slide and change the menu status (key)

Call invalideoptionsmenu(); Method to load the menu again, that is, callback the onprepareoptionsmenu method

Code (Reference)

It is the demo with viewpager created by Android studio by default,

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
分享
二维码
< <上一篇
下一篇>>