android7.1 shotcuts,Android N App Shotcuts 学习
()一:
Android 7.1 增加了很多新特性,比如多窗口,App Shotcuts….
其中,App Shoutcuts就類似于iphone手機(jī)上3D Touch功能,在應(yīng)用桌面長按某個(gè)app圖標(biāo),就會(huì)對(duì)應(yīng)的彈出選項(xiàng),使我們操作更加方便和快速;
先來張圖看看安卓的App Shotcuts長什么樣:
圖片引用官網(wǎng),長按短信圖標(biāo)彈出的選項(xiàng)。
二:
自己實(shí)踐為自己的app添加App Shortcuts功能,前提條件必須是android 7.1,api 25
App ShortCuts 實(shí)現(xiàn)有兩種:
1,xml 布局
2,代碼實(shí)現(xiàn)
先來講xml布局實(shí)現(xiàn):
1.首先在自己的清單文件(activity 主入口)下,加入一個(gè) 標(biāo)簽
2.然后再res目錄下新建一個(gè)xml文件夾,隨后創(chuàng)建一個(gè)xml文件,取名就是上面的引用
android:shortcutId="add_website" //id
android:icon="@drawable/ic_launcher" //圖標(biāo)
android:shortcutShortLabel="@string/shortcuts"
android:shortcutLongLabel="@string/shortcutss" //名字
>
android:action="com.example.android.appshortcuts.ADD_WEBSITE"
android:targetPackage="com.example.administrator.myapplication" //包名
android:targetClass="com.example.administrator.myapplication.MainActivity" //類名
/>
3.到這一步,基本上就已經(jīng)完成了App Shortcuts的功能,然后打開7.1模擬器run
4.這樣就可以了,如果想添加多個(gè)選項(xiàng),怎么辦?依然在xml文件中修改(注意,shortcutiId不要一樣)
android:shortcutId="add_website"
android:icon="@drawable/ic_launcher"
android:shortcutShortLabel="@string/shortcuts"
android:shortcutLongLabel="@string/shortcutss"
>
android:action="com.example.android.appshortcuts.ADD_WEBSITE"
android:targetPackage="com.example.administrator.myapplication"
android:targetClass="com.example.administrator.myapplication.MainActivity"
/>
android:shortcutId="add_website1"
android:icon="@drawable/ic_launcher"
android:shortcutShortLabel="@string/shortcuts"
android:shortcutLongLabel="@string/shortcutss"
>
android:action="com.example.android.appshortcuts.ADD_WEBSITE"
android:targetPackage="com.example.administrator.myapplication"
android:targetClass="com.example.administrator.myapplication.MainActivity"
/>
android:shortcutId="add_website2"
android:icon="@drawable/ic_launcher"
android:shortcutShortLabel="@string/shortcuts"
android:shortcutLongLabel="@string/shortcutss"
>
android:action="com.example.android.appshortcuts.ADD_WEBSITE"
android:targetPackage="com.example.administrator.myapplication"
android:targetClass="com.example.administrator.myapplication.MainActivity"
/>
如下圖:
三:
如果代碼實(shí)現(xiàn)?其實(shí)也很簡單,如下
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));
總結(jié)
以上是生活随笔為你收集整理的android7.1 shotcuts,Android N App Shotcuts 学习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于android的视频采集系统的设计与
- 下一篇: android异步线程未执行,关于多线程