Android7.1.1新功能 如何编写shortcuts脚本讲解

       要想实现此功能,首先新建1个命名为shortcuts的XMI脚本(必须命名为"shortcu

t"

示例如下(将文件放入layout目录中)

<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
    <shortcut
        android:enabled="true"
        android:icon="显示图标"
        android:shortcutDisabledMessage="@string/disable_hint_message"
        android:shortcutId="shortcut1"
        android:shortcutLongLabel="@string/long_label_one"
        android:shortcutShortLabel="@string/short_label_one">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.example.helloworld.RecyclerViewTestActivity"
            android:targetPackage="com.example.helloworld">
            <extra
                android:name="key1"
                android:value="value1" />
        </intent>
    </shortcut>

    <shortcut
        android:enabled="true"
        android:icon="显示图标1"
        android:shortcutDisabledMessage="@string/disable_hint_message"
        android:shortcutId="shortcut2"
        android:shortcutLongLabel="@string/long_label_two"
        android:shortcutShortLabel="@string/short_label_two">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.example.helloworld.TestViewPagerActivity"
            android:targetPackage="com.example.helloworld">
            <extra
                android:name="key2"
                android:value="value2" />
        </intent>
    </shortcut>
</shortcuts>
<string name="short_label_one">名称</string>
<string name="short_label_two">名称1</string>
<string name="long_label_one">附名称</string>
<string name="long_label_two">附名称1</string>
<string name="disable_hint_message">你确认要禁用该快捷方式吗?</string>

  第二步,在软件目录AndroidManifest中添加以下代码(适当行列)

<activity
   android:name=".MainActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data
        android:name="android.app.shortcuts"
        android:resource="文件路径" />
</activity>

工程基本完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值