简体   繁体   English

Android如何为按钮添加徽章

[英]Android how to add badge to button

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"/>

Need to set the compound drawable of the button.需要设置按钮的复合drawable。 Take a look at this and this for better understandment.看看thisthis以便更好地理解。 If u have any more questions.如果您还有其他问题。 ask.问。

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也检查这个问题

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检查更多https://material.io/develop/android/components/badging

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM