Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Showing number of new items count on tabs

I have an android application where the home screen is a tab view. One of the tab goes to an "Inbox" activity. I'd like to show a number that indicates the number new messages. This seem to be a standard feature on iPhone apps. Is there any sort of system support for this? If not, what's the easiest way to implement this effect for android tabviews?

like image 275
tstyle Avatar asked Nov 06 '22 05:11

tstyle


1 Answers

From what I can read in the Android Sourcecode (TabHost.java) there is no way to do it with standard widgets in a similar fashion like iPhone.

What you could do is:

  1. Whenever the inbox count was changed, delete all tabs using http://developer.android.com/reference/android/widget/TabHost.html#clearAllTabs()
  2. Then, create the tabs again using http://developer.android.com/reference/android/widget/TabHost.html#addTab(android.widget.TabHost.TabSpec) but make sure the TabSpec is initialized with [http://developer.android.com/reference/android/widget/TabHost.TabSpec.html#setIndicator(java.lang.CharSequence, android.graphics.drawable.Drawable)][1] . You can pass your own drawable there and use it to paint the badge yourself.

It's no replacement for the iPhone Style badge though, as the iPhone badge is quite nicely in the topRight corners of the label. And so far there is no way to change it.

On the other hand, this being all Java someone could extend the TabHost class and add support for iPhone style badges.

[1]: http://developer.android.com/reference/android/widget/TabHost.TabSpec.html#setIndicator(java.lang.CharSequence, android.graphics.drawable.Drawable)

like image 74
Sebastian Roth Avatar answered Nov 11 '22 12:11

Sebastian Roth