gpt4 book ai didi

android - 多种口味的静态android快捷方式?

转载 作者:IT老高 更新时间:2023-10-28 23:15:00 25 4
gpt4 key购买 nike

是否可以在不复制快捷方式.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>

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

为了还提供免费风格的快捷方式,我必须复制 shortcuts.xml 并将targetPackage 更改为com.test。免费这是一个糟糕的解决方案。

最佳答案

我创建了一个插件,可以在资源中使用 manifestPlaceholders,并且可以与 3.0.0 版的 android gradle 插件一起使用

https://github.com/timfreiheit/ResourcePlaceholdersPlugin

src/main/res/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="${applicationId}"/>
</shortcut>

关于android - 多种口味的静态android快捷方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40361296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com