Search code examples
androidandroid-tabhostandroid-xmlandroid-tabs

Add indicator dynamically to tabhost icon android


I am using Tabhost in Android app for navigation. All works well, however one of my tabs is for Messages and if the user has at least 1 message, I'd like to add a textview to the tab icon showing the number of messages the user has. So basically I have the icon and the text Messages below, and would like to have an additional textview on the top right of the tab icon showing the message count.

I've found posts related to adding text to the tab, however it merely modifies the existing tab indicator textview. Is it possible to have an additional textview on the tab that I can reference and have set to visibility gone normally, and if messages exist update the visibility to visible and show the count?

I'm guessing I'll need to create a custom XML layout for this tab and use it when calling

.setIndicator("Messages",res.getDrawable(R.drawable.tab_messages))

Any insight or examples are greatly appreciated, thank you!!


Solution

  • Please check this example it's work. It's display badge in your tabbar

    TAB_BAR SHOWING NUMBER