亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

Android7.1圖標(biāo)快捷方式(AppShortcuts)實現(xiàn)Demo

afishhhhh / 2306人閱讀

摘要:今天給手上的手機升級系統(tǒng)至體驗了一下新功能圖標(biāo)快捷方式如下圖所示如何實現(xiàn)這樣的快捷方式呢官方給出的實現(xiàn)步驟分類圖標(biāo)快捷方式分為兩種靜態(tài)快捷方式動態(tài)快捷方式靜態(tài)快捷方式是寫在文件中而動態(tài)快捷方式是在代碼中編寫實現(xiàn)環(huán)境要求只有及以上手機才能使用

今天給手上的Nexus6P手機升級系統(tǒng)至Android7.1,體驗了一下新功能:App Shortcuts(圖標(biāo)快捷方式),如下圖所示:

如何實現(xiàn)這樣的快捷方式呢?

官方給出的實現(xiàn)步驟:App Shortcuts | Android Developers

分類

圖標(biāo)快捷方式(App Shortcuts)分為兩種:

Static shortcuts(靜態(tài)快捷方式)

Dynamic shortcuts(動態(tài)快捷方式)

靜態(tài)快捷方式是寫在xml文件中,而動態(tài)快捷方式是在Java代碼中編寫.

實現(xiàn) 環(huán)境要求

只有Android7.1(25)及以上手機才能使用該功能

要求SDK版本為25及以上

最低兼容版本為23(因為動態(tài)快捷方式使用Icon類)

module 的build.gradle配置如下:

apply plugin: "com.android.application"

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "net.devwiki.shortcuts"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:25.0.0"
    testCompile "junit:junit:4.12"
}
靜態(tài)快捷方式

1.在項目的res/文件夾下建立 xml目錄

2.在xml目錄創(chuàng)建shortcuts.xml文件,內(nèi)容如下



    
        
        
        
    
    

屬性含義和圖片說明如下:

shortcutId : 快捷方式的ID
enabled : 是否可用,不可用時點擊Toast提示shortcutDisabledMessage
icon : 快捷方式圖標(biāo)
shortcutShortLabel : 快捷圖標(biāo)放置到桌面時的標(biāo)題
shortcutLongLabel : 長按圖標(biāo)出現(xiàn)快捷方式時的標(biāo)題
shortcutDisabledMessage : 快捷圖標(biāo)禁用時的提示語

3.在AndroidManifest.xml文件中設(shè)置靜態(tài)快捷方式



    
        
            
                

                
            
            
        
        
        
    
動態(tài)快捷方式

動態(tài)快捷方式即在代碼中添加,更新快捷圖標(biāo).

ShortcutManager提供了添加,移除,更新,禁用,啟動,獲取靜態(tài)快捷方式,獲取動態(tài)快捷方式,獲取固定在桌面的快捷方式等方法.
可在Java代碼中動態(tài)對圖標(biāo)快捷方式進行操作.

添加快捷方式

private void addShortcut() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        List infoList = shortcutManager.getDynamicShortcuts();
        String shortcutId = null;
        for (ShortcutInfo shortcutInfo : infoList) {
            if (ShortcutsId.WEB_DEVWIKI.equals(shortcutInfo.getId())) {
                shortcutId = shortcutInfo.getId();
            }
        }
        if (shortcutId == null) {
            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, ShortcutsId.WEB_DEVWIKI)
                    .setShortLabel(getString(R.string.blog_short_label))
                    .setLongLabel(getString(R.string.blog_long_label))
                    .setIcon(Icon.createWithResource(this, R.drawable.ic_blog_logo))
                    .setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://blog.devwiki.net")))
                    .build();
            shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
            Toast.makeText(this, R.string.add_shortcut_success, Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, R.string.shortcut_already_exist, Toast.LENGTH_SHORT).show();
        }
    } else {
        Toast.makeText(this, R.string.not_support_function, Toast.LENGTH_SHORT).show();
    }
}

移除快捷方式

private void removeShortcut() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        List infoList = shortcutManager.getDynamicShortcuts();
        String shortcutId = null;
        for (ShortcutInfo shortcutInfo : infoList) {
            if (ShortcutsId.WEB_DEVWIKI.equals(shortcutInfo.getId())) {
                shortcutId = shortcutInfo.getId();
            }
        }
        if (shortcutId == null) {
            Toast.makeText(this, R.string.shortcut_not_exist, Toast.LENGTH_SHORT).show();
        } else {
            shortcutManager.removeDynamicShortcuts(Arrays.asList(shortcutId));
            Toast.makeText(this, R.string.remove_shortcut_success, Toast.LENGTH_SHORT).show();
        }
    } else {
        Toast.makeText(this, R.string.not_support_function, Toast.LENGTH_SHORT).show();
    }
}
項目代碼

項目代碼在此處:Shortcuts

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/66250.html

相關(guān)文章

  • 淺談 CSS Sprites 雪碧圖應(yīng)用

    摘要:編寫配置文件,以下是關(guān)鍵配置代碼雪碧圖合并輸出到文件參數(shù)執(zhí)行目錄參數(shù)生成的和圖片的文件名之所以推薦,是因為非常的靈活,看懂模塊的可以根據(jù)你的項目情況編寫對應(yīng)的配置文件。 showImg(https://segmentfault.com/img/bVGpAw?w=518&h=156); 前言 網(wǎng)站開發(fā)90%會用到小圖標(biāo), 多小圖標(biāo)調(diào)用顯示是前端開發(fā)常見的問題;目前小圖標(biāo)顯示常見有兩種方式...

    MkkHou 評論0 收藏0
  • ESP32 ESP-IDF開發(fā)環(huán)境搭建,Windows下基于ESP-IDF | Cmake | VS

    摘要:之前一篇博客搭建開發(fā)環(huán)境發(fā)布后,深受好評。樂鑫官方提供插件,一站式安裝,直接將升格為,配合上原有的插件主題,的過程十分愜意。目前已開放預(yù)覽版本,功能涵蓋等外設(shè)驅(qū)動,下一步準(zhǔn)備擴充解碼庫有線以太網(wǎng)和一些網(wǎng)絡(luò)通信的。 ...

    TalkingData 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<