小编And*_*Roß的帖子

多种口味的静态android快捷键?

是否可以为多种口味定义静态快捷方式而无需复制shortcuts.xml?我有两种口味:

  • main(包:com.test)
  • 免费(包:com.test.free)

shortcuts.xml看起来是这样的:

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
    android:enabled="true"
    android:icon="@drawable/ic_shortcut_add_photo"
    android:shortcutId="new_photo"
    android:shortcutLongLabel="@string/new_photo"
    android:shortcutShortLabel="@string/new_photo">

    <intent
        android:action="android.intent.action.VIEW"
        android:targetClass="com.test.MainActivity"
        android:targetPackage="com.test"/>
</shortcut>
Run Code Online (Sandbox Code Playgroud)

问题是intent中的包名称不能引用字符串资源,必须在xml中进行硬编码.

为了还为自由的味道,我必须提供快捷方式复制shortcuts.xml并更改targetPackage到com.test.free这是一个坏的解决方案.

xml android android-shortcut

20
推荐指数
3
解决办法
1679
查看次数

标签 统计

android ×1

android-shortcut ×1

xml ×1