MIUI6&7桌面角標開源代碼簡介

2018-02-25 14:23 更新

MIUI6&7桌面角標開源代碼簡介

MIUI6&7上重新設計了桌面app圖標的角標顯示,基本規(guī)則如下:

一、基本介紹

1、默認的情況

當app 向通知欄發(fā)送了一條通知 (通知不帶進度條并且用戶可以刪除的),那么桌面app icon角標就會顯示1.此時app顯示的角標數(shù)是和通知欄里app發(fā)送的通知數(shù)對應的,即向通知欄發(fā)送了多少通知就會顯示多少角標。

2、通知可以定義角標數(shù)

例如 有5封未讀郵件,通知欄里只會顯示一條通知,但是想讓角標顯示5. 可以在發(fā)通知時加個標示。

二、實現(xiàn)代碼

第三方app需要用反射來調(diào)用,參考代碼:

NotificationManager mNotificationManager = (NotificationManager) this

.getSystemService(Context.NOTIFICATION_SERVICE);

Notification.Builder builder = new Notification.Builder(this)

.setContentTitle(“title”).setContentText(“text”).setSmallIcon(R.drawable.icon);

Notification notification = builder.build();

try {

Field field = notification.getClass().getDeclaredField(“extraNotification”);

Object extraNotification = field.get(notification);

Method method = extraNotification.getClass().getDeclaredMethod(“setMessageCount”, int.class);

method.invoke(extraNotification, mCount);

} catch (Exception e) {

e.printStackTrace();

}

mNotificationManager.notify(0,notification);

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號