Android 8.0新特性 桌面圖標菜單Shortcuts

前言

最近更新了Android8.0,發(fā)現(xiàn)了有個新功能,就是桌面圖標上長安可以彈出菜單,如圖。點擊可進入相應的頁面。作為程序員你肯定想知道這是怎么做出來的吧,于是我就翻過去看了看。


系統(tǒng)

正文

? ? ? ? ? ? 這個功能叫做APP?Shortcuts,有兩種注冊的方法,靜態(tài)注冊和動態(tài)注冊。

1.靜態(tài)注冊

在啟動界面的下添加 meta-data標簽


在xml文件下新建xml文件shortcut.xml


搞定

2.動態(tài)注冊

添加

ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1") ? ? .setShortLabel("Web site") ? ? .setLongLabel("Open the web site") ? ? .setIcon(Icon.createWithResource(context, R.drawable.icon_website)) ? ? .setIntent(new Intent(Intent.ACTION_VIEW, ? ? ? ? ? ? ? ? ? ?Uri.parse("https://www.mysite.example.com/"))) ? ? .build(); shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));

移除

shortcutManager.disableShortcuts(Arrays.asList("news","email","search","web"));???????


example:



結(jié)語

其實很簡單,還有其他的一些API請到谷歌開發(fā)者中心區(qū)查看吧,英語不好,看不太懂。

Github:https://github.com/jessing/LaucherBadgeDemo/tree/master

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容