Android 桌面图标长按快捷菜单
生活随笔
收集整理的這篇文章主要介紹了
Android 桌面图标长按快捷菜单
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
為了更快使用APP的某個(gè)功能,在手機(jī)桌面長(zhǎng)按圖標(biāo)呼出快捷菜單
需要注意:在7.0以上的系統(tǒng)才支持該功能
ShortcutManagerCompat方式實(shí)現(xiàn):AndroidX版本
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {List<ShortcutInfoCompat> shortcutInfoList = new ArrayList<>();ShortcutInfoCompat.Builder builder = new ShortcutInfoCompat.Builder(this,"這里設(shè)置唯一標(biāo)識(shí)就可以,內(nèi)容隨意");builder.setShortLabel("快捷菜單1").setIcon(IconCompat.createWithResource(this, R.mipmap.ic_launcher)).setIntent(new Intent(Intent.ACTION_MAIN, null,this,SttActivityGoogle.class));shortcutInfoList.add(builder.build());ShortcutManagerCompat.addDynamicShortcuts(this,shortcutInfoList);}ShortcutManager方式實(shí)現(xiàn):
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(this, "這里設(shè)置唯一標(biāo)識(shí)就可以,內(nèi)容隨意")//唯一標(biāo)識(shí)id.setShortLabel("快捷菜單")//短的標(biāo)簽.setLongLabel("快捷菜單123")//長(zhǎng)的標(biāo)簽.setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))//圖標(biāo).setIntent(new Intent(this, NiuHaoActivity.class))//跳轉(zhuǎn)的目標(biāo),這里我設(shè)置的是當(dāng)前.build();activity.getSystemService(ShortcutManager.class).setDynamicShortcuts("這里設(shè)置list,轉(zhuǎn)換一下即可");}總結(jié)
以上是生活随笔為你收集整理的Android 桌面图标长按快捷菜单的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 搭建java开发环境
- 下一篇: Spring Security 初体验