shortcut

官方地址

设置静态shortcut

这里写图片描述

AndroidManifest.xml 添加meta-data ,如下

<activity android:name=".MainActivity">
            <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="@xml/shortcuts"/>
        </activity>

新建res/xml/shortcuts.xml ,,,StaticShortcut 是自己的项目名称这里写图片描述

<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
    <shortcut
        android:shortcutId="compose"
        android:enabled="true"
        android:icon="@mipmap/ic_launcher"
        android:shortcutShortLabel="@string/compose_shortcut_short_label1"
        android:shortcutLongLabel="@string/compose_shortcut_long_label1"
        android:shortcutDisabledMessage="@string/compose_disabled_message1">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.example.myapplication"
            android:targetClass="com.example.myapplication.StaticShortcut" />
        <!-- If your shortcut is associated with multiple intents, include them
             here. The last intent in the list determines what the user sees when
             they launch this shortcut. -->
        <categories android:name="android.shortcut.conversation" />
    </shortcut>
    <!-- Specify more shortcuts here. -->
</shortcuts>

注意:不可以在资源文件里直接写标签名称,应该链接 string.xml 这种目录
这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_38340601/article/details/82712016