<强> & # 65279;>强角标,英语是徽章,也就是“徽章,像章,奖章;象征,标记”的意思。
<>强效果图强>
& lt; uses-permission android: name=" com.sec.android.provider.badge.permission。读作“/比; & lt; uses-permission android: name=" com.sec.android.provider.badge.permission。写“/祝辞
设置角标和清除角标的工具类
公开课BadgeUtils { 私有静态最终字符串INTENT_ACTION=癮ndroid.intent.action.BADGE_COUNT_UPDATE”; 私有静态最终字符串INTENT_EXTRA_BADGE_COUNT=癰adge_count”; 私有静态最终字符串INTENT_EXTRA_PACKAGENAME=癰adge_count_package_name”; 私有静态最终字符串INTENT_EXTRA_ACTIVITY_NAME=癰adge_count_class_name”;//设置角标 公共静态孔隙setBadgeCount(上下文语境,int badgeCount) { 目的意图=new意图(INTENT_ACTION); 意图。putExtra (INTENT_EXTRA_BADGE_COUNT badgeCount); 意图。putExtra (INTENT_EXTRA_PACKAGENAME getComponentName(上下文).getPackageName ()); 意图。putExtra (INTENT_EXTRA_ACTIVITY_NAME getComponentName(上下文).getClassName ()); context.sendBroadcast(意图); }//清除角标 公共静态孔隙removeBadge(上下文语境){ setBadgeCount(上下文,0); }//获取ComponentName 私有静态ComponentName getComponentName(上下文语境){ 返回context.getApplicationContext () .getPackageManager () .getPackageName .getLaunchIntentForPackage (context.getApplicationContext () ()) .getComponent (); } } >之前注意:
因为不同手机厂商的行动不同,所以可能导致某些手机不能使用,在此推荐一个github的第三方库:https://github.com/leolin310148/ShortcutBadger
github地址:https://github.com/zhouxu88/AppBadge
完整演示下载地址:AppBadge_jb51。rar
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
Android为应用添加数字角标的简单实现