Android how to add badge to button
12,530
Solution 1
Use this library
Sample example provided by library
View target = findViewById(R.id.target_view);
BadgeView badge = new BadgeView(this, target);
badge.setText("1");
badge.show();
Also check this Question
Solution 2
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
Solution 3
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.
Related videos on Youtube
Author by
Christine
Updated on September 28, 2022Comments
-
Christine over 1 year
I want to add a badge in my button, how can i do that ?
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"/>
-
Umair almost 9 yearscheck this stackoverflow.com/questions/6011786/…
-