0

0

0

修罗

站点介绍

只有了解事实才能获得真正的自由

BGABadgeView-Android给控件添加红点

修罗 2023-02-07 686 0条评论 安卓

首页 / 正文

1690366486009.png

依赖

//给控件添加未读消息数红点
//https://github.com/bingoogolapple/BGABadgeView-Android
implementation 'com.github.bingoogolapple.BGABadgeView-Android:api:1.2.0'
annotationProcessor 'com.github.bingoogolapple.BGABadgeView-Android:compiler:1.2.0'

给控件添加红点

随便放在哪个包中,运行一下应用,即可生成相关控件

/**
 * 初始化给控件添加未读消息数红点
 */
@BGABadge({
        // 给ImageView.TextView添加未读消息数红点
        ImageView.class, // 对应 cn.bingoogolapple.badgeview.BGABadgeImageView
        TextView.class // 对应 cn.bingoogolapple.badgeview.BGABadgeFloatingTextView
})
public class BadgeInit { }

使用

1690366486009.png

<cn.bingoogolapple.badgeview.BGABadgeImageView
            android:id="@+id/left_button"
            android:layout_width="@dimen/super_title_icon_width"
            android:layout_height="@dimen/super_title_icon_width"
            android:layout_centerVertical="true"
            android:padding="@dimen/padding_small"
            android:src="@drawable/menu" />

显示未读数

showMessageUnreadCount(12)

// 未读数在控件显示
public void showMessageUnreadCount(Integer unReadCount) {
    if (unReadCount > 0) {
        // 大于99显示99+
        String messageCount= StringUtil.formatMessageCount(unReadCount);

        binding.leftButton.showTextBadge(messageCount);
    }else{
        binding.leftButton.hiddenBadge();
    }
}

评论(0)


最新评论

  • 1

    1

  • 1

    1

  • -1' OR 2+158-158-1=0+0+0+1 or 'TKCTZnRa'='

    1

  • 1

    1

  • 1

    1

  • 1

    1

  • 1

    1

  • @@5Qa2D

    1

  • 1

    1

  • 1

    1

日历

2025年09月

 123456
78910111213
14151617181920
21222324252627
282930    

文章目录

推荐关键字: Linux webpack js 算法 MongoDB laravel JAVA jquery javase redis