Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to add badge to button

I want to add a badge in my button, how can i do that ?

enter image description here

Button :

                    <Button
                    android:id="@+id/button"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:background="@drawable/badge_circle"
                    android:gravity="center"
                    android:padding="12dip"
                    android:text="Button"
                    android:textColor="#ffffff"/>
like image 829
Christine Avatar asked Jun 04 '15 07:06

Christine


2 Answers

You can use this

BadgeDrawable badgeDrawable =  BadgeDrawable.create(getContext());
badgeDrawable.setNumber(3);
badgeDrawable.setVisible(true);
BadgeUtils.attachBadgeDrawable(badgeDrawable, tragetView);

check for more https://material.io/develop/android/components/badging

like image 103
Moumen Lahmidi Avatar answered Oct 30 '22 10:10

Moumen Lahmidi


Need to set the compound drawable of the button. Take a look at this and this for better understandment. If u have any more questions. ask.

like image 24
EE66 Avatar answered Oct 30 '22 09:10

EE66