Android – 尝试添加应用程序快捷方式时出错

我的应用有minSdk = 21和targetSdk = 26

我想设置应用程序快捷方式

添加了<元数据>标记应用程序启动时启动的第一个活动.

<activity android:name=".SignInActivity"
            android:theme="@style/SubscriptionsTheme.NoActionBar">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.MAIN"/>
            </intent-filter>
            <Meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
        </activity>

然后我创建了xml-v25目录,并在其中创建了这个shortcuts.xml文件

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
    <shortcut
        android:shortcutId="test"
        android:icon="@drawable/plus"
        android:shortcutShortLabel="test"
        android:shortcutLongLabel="long test" >

        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.xxxxx.xxxxx.xxxxx"
            android:targetClass="com.xxxxx.xxxxx.xxxxxx.main" />

    </shortcut>
</shortcuts> 

当我尝试构建应用程序时,我收到以下错误

Error:error: ‘long test’ is incompatible with attribute
android:shortcutLongLabel (attr) reference.
Error:error: ‘test’ is incompatible with attribute android:shortcutShortLabel (attr) reference.
Error:’long test’ is incompatible with attribute android:shortcutLongLabel (attr) reference.

解决方法:

希望这可以帮助.

strings.xml

 <string name="long_shortcut">long test</string>
  <string name="short_shortcut">test</string>

在Manifest.xml中使用此字符串的引用

<shortcut
        android:shortcutId="test"
        android:icon="@drawable/plus"
        android:shortcutShortLabel="@string/short_shortcut"
        android:shortcutLongLabel="@string/long_shortcut" >

在java中,您还可以使用ShortcutInfo.Builder的setLongLabel(CharSequence longLabel)和setShortLabel(CharSequence)来分配它.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...