簡體   English   中英

Android如何為按鈕添加徽章

[英]Android how to add badge to 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"/>

需要設置按鈕的復合drawable。 看看thisthis以便更好地理解。 如果您還有其他問題。 問。

使用這個

庫提供的示例示例

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

也檢查這個問題

你可以用這個

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM