Android如何添加徽章到按钮

时间:2015-06-04 07:11:26

标签: android android-layout

我想在我的按钮中添加徽章,我该怎么做?

enter image description here

按钮:

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

3 个答案:

答案 0 :(得分:1)

需要设置按钮的复合drawable。 请查看thisthis以获得更好的理解。 如果你还有其他问题。问。

答案 1 :(得分:1)

使用此library

库提供的示例示例

View target = findViewById(R.id.target_view);
BadgeView badge = new BadgeView(this, target);
badge.setText("1");
badge.show();

同时检查此Question

答案 2 :(得分:0)

您可以使用此

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

检查更多https://material.io/develop/android/components/badging

相关问题