Skip to content

Instantly share code, notes, and snippets.

@pacificregmi
Created January 21, 2016 06:39
Show Gist options
  • Save pacificregmi/971e1a46430d35ead22d to your computer and use it in GitHub Desktop.
Save pacificregmi/971e1a46430d35ead22d to your computer and use it in GitHub Desktop.
Adding Badge (Item Count) to Android Button - badge_item_notification_count_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<!--Adding Badge (Item Count)/Notification Count to Android Button-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp">
<RelativeLayout
android:id="@+id/badge_layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="65dip"
android:layout_height="65dip"
android:background="@drawable/notification_icon" />
</RelativeLayout>
<TextView
android:id="@+id/badge_notification_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/relative_layout"
android:background="@drawable/badge_item_count"
android:text="27"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/badge2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_toRightOf="@+id/badge_layout1">
<RelativeLayout
android:id="@+id/relative_layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/myButton1"
android:layout_width="65dip"
android:layout_height="65dip"
android:background="@drawable/email_icon" />
</RelativeLayout>
<TextView
android:id="@+id/badge_notification_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/relative_layout1"
android:background="@drawable/badge_item_count"
android:text="11"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/badge3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_toRightOf="@+id/badge2">
<RelativeLayout
android:id="@+id/relative_layout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/myButton3"
android:layout_width="65dip"
android:layout_height="65dip"
android:background="@drawable/promotion_ic" />
</RelativeLayout>
<TextView
android:id="@+id/badge_notification_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/relative_layout2"
android:background="@drawable/badge_item_count"
android:text="55"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/badge4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/badge_layout1"
android:layout_marginTop="50dp">
<RelativeLayout
android:id="@+id/relative_layout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/myButton4"
android:layout_width="wrap_content"
android:layout_height="65dip"
android:background="#72b332"
android:elevation="4dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text="Notification Badge Android"
android:textColor="#fff" />
</RelativeLayout>
<TextView
android:id="@+id/badge_notification_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/relative_layout3"
android:background="@drawable/badge_item_count"
android:text="1030"
android:textColor="#FFF"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment