开发者

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.

Android Tab Bar

If badges is not available in android, is placing a view in front of tab bar a fine solu开发者_StackOverflow社区tion?


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


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.


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.


Is Notification.number what you're looking for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜