Manikandan
Manikandan

Reputation: 4388

Android Tab Bar

Is there any possibility to add notification in android tab bar like in iPhone Badges for tabs. I am not mean notification.Here i will place the iPhone badges screen shot also.enter image description here

If badges is not available in android, is placing a view in front of tab bar a fine solution?

Upvotes: 0

Views: 1395

Answers (4)

Rudi
Rudi

Reputation: 4314

You can create a custom Tab item xml and put a RelativeLayout with a background image and a centerInParent textView. Set RelativeLayout's visibility to GONE and whenever you want to show it, make it visible and set that textview to any text you want to.

<RelativeLayout
        android:id="@+id/tabBadge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="47dp"
        android:layout_marginTop="10dp"
        android:layout_toStartOf="@+id/tabTitle"
        android:visibility="gone" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@drawable/basket_item"
            android:contentDescription="@string/action_settings" />

        <TextView
            android:layout_centerInParent="true"
            android:id="@+id/tabBadgeText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textColor="#ffffff"
            android:textSize="10sp" />
    </RelativeLayout> 

Also make sure to set that Relativelayout in your code while you are generating your tag like the code below so you can access to it whenever you want to:

// mTitle is the title of the tab

if (mTitle.equalsIgnoreCase("Basket")) {

//count is the TextView inside your badge

count = (TextView) view.findViewById(R.id.tabBadgeText);

//layout is the whole badge's layout

layout = (RelativeLayout) view.findViewById(R.id.tabBadge);

}

Hope it helps, if you need more information please feel free to ask.

Upvotes: 0

salman khalid
salman khalid

Reputation: 4934

The possible way of doing this is to include android-viewbadger.jar in your Android Project and then using BadgeView Object.

Upvotes: 2

Adeel Pervaiz
Adeel Pervaiz

Reputation: 1356

There's no way to add a badge or small view on tabs. However you can create custom tabs and to add those tab on every view, override setContentView() in every activity and handle your custom tabs before setting content view.

Upvotes: 1

Felix
Felix

Reputation: 89566

Is Notification.number what you're looking for?

Upvotes: -1

Related Questions