Android中实现标题栏红点通知功能
添加依赖
implementation 'com.github.bingoogolapple.BGABadgeView-Android:api:1.2.0'
annotationProcessor 'com.github.bingoogolapple.BGABadgeView-Android:compiler:1.2.0'
配置
@BGABadge({
ImageView.class,
TextView.class
})
public class BadgeInit {
}
更改控件
<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/d5"
android:src="@drawable/menu"
/>
显示/隐藏
public void showMessageUnreadCount(Integer unReadCount) {
if (unReadCount > 0) {
String messageCount= StringUtil.formatMessageCount(unReadCount);
binding.indicator.showMsg(0,unReadCount);
binding.leftButton.showTextBadge(messageCount);
}else{
binding.indicator.hideMsg(0);
binding.leftButton.hiddenBadge();
}
}