You can use badgeview to display the number of messages on the actionbar menu.
The implementation method is to obtain the view of the actionbar menuitem and then create the badgeview. Note: Generally, you can only obtain the menuitem view after optionsmenu is created. We can delay processing in the oncreate method by 1 second.
<Menu xmlns: Android = "http://schemas.android.com/apk/res/android"
Xmlns: APP = "http://schemas.android.com/apk/res-auto"
Xmlns: Tools = "http://schemas.android.com/tools"
Tools: context = "com. example. Demo. mainactivity">
<Item
Android: Id = "@ + ID/action_settings"
Android: orderincategory = "100"
Android: Title = "@ string/action_settings"
APP: showasaction = "always"/>
</Menu>
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity_main );
New handler (). postdelayed (New runnable (){
@ Override
Public void run (){
View view = findviewbyid (R. Id. action_setting );
Badgeview = new badgeview (mainactivity. This, view );
Badgeview. settext ("1 ");
Badgeview. Show ();
}
},1000 );
}
:
Use badgeview to display reminder information on actionbar menu