naresh
naresh

Reputation: 10402

How to set the badge position in tabs

I am new to badge's concept. In my application i want to show the badges on the tabs. For that i used the android-viewbadger.jar file. It's working fine but position property is not effected. How to set the position. If you need more info please let me know.

TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);       
DH_Constant.badgeView = new BadgeView(this, tabs, 2);

// it's working fine

badge1.setBadgePosition(BadgeView.POSITION_CENTER);

// But I Supposed to set it as position to top_left or top_right then it still shows as bottom_left and bottom_right

badge1.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);

DH_Constant.badgeView.setText(DH_Constant.MessagesCount_obj.count); 
DH_Constant.badgeView.show();

Output:

enter image description here

Upvotes: 0

Views: 2616

Answers (2)

neurofen
neurofen

Reputation: 41

To get badge position to show in top corner of your tab you need to set the root of your tab layout to FrameLayout like so:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout 
    android:id="@+id/tabsLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/tabs_background"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dip" >

    <ImageView
        android:id="@+id/tabsIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/tab_icon"
        android:duplicateParentState="true" />

    <TextView
        android:id="@+id/tabsText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/tabs_text"
        android:textSize="10dip"
        android:textStyle="bold" />

</LinearLayout>

Upvotes: 0

salman khalid
salman khalid

Reputation: 4934

By default it's position is TOP_RIGHT. If you want any other position you have to set that. e.g For top_left use:

badge1.setBadgePosition(BadgeView.POSITION_TOP_LEFT);

For center use:

badge1.setBadgePosition(BadgeView.POSITION_CENTER);

For bottom_left use:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_LEFT);

For bottom_right use:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_RIGHT);

Upvotes: 4

Related Questions