英文:
Changing the application icon dynamically with activity alias
问题
我在API中有两个图标,并且当按下按钮1时,我希望应用程序图标是API中的第一个图标,当按下按钮2时,是API中的第二个图标。我该如何实现这个功能?
我无法通过API实现这一点,但我成功地保存了本地图标并使用别名来使用它们。
<activity-alias
android:name="OneLauncherAlias"
android:targetActivity=".MainActivity"
android:icon="@mipmap/ic_launcher_verisoft1"
android:label="@string/verisoft_name"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity-alias>
英文:
I have two icons in the API, and I want the application icon to be the 1st icon from the API when Button 1 is pressed, and the 2nd icon from the API when Button 2 is pressed. How can I achieve this?
I couldn't achieve it using the API, but I managed to save the local icons and use them with aliases.
<activity-alias
android:name="OneLauncherAlias"
android:targetActivity=".MainActivity"
android:icon="@mipmap/ic_launcher_verisoft1"
android:label="@string/verisoft_name"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity-alias>
答案1
得分: 2
你可以通过以下方法动态更改应用程序的图标和名称。
<activity-alias
android:name=".SplashActivityAlias1"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/ic_launcher_1"
android:label="Calculator"
android:roundIcon="@mipmap/ic_launcher_1"
android:targetActivity=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:name=".SplashActivityAlias2"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/ic_launcher_2"
android:label="Calculator"
android:roundIcon="@mipmap/ic_launcher_2"
android:targetActivity=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
您需要为启动器活动添加多个别名,以更改多个图标。像这样。
val pm = packageManager
pm.setComponentEnabledSetting(
ComponentName(
this,
"com.photovideolocker.SplashActivity"
),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
pm.setComponentEnabledSetting(
ComponentName(
this,
"com.photovideolocker.SplashActivityAlias1"
),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
pm.setComponentEnabledSetting(
ComponentName(
this,
"com.photovideolocker.SplashActivityAlias2"
),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
您可以通过此方法启用和禁用要设置的图标。
英文:
You can change the App Icon and Name dynamically by following method.
<activity-alias
android:name=".SplashActivityAlias1"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/ic_launcher_1"
android:label="Calculator"
android:roundIcon="@mipmap/ic_launcher_1"
android:targetActivity=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:name=".SplashActivityAlias2"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/ic_launcher_2"
android:label="Calculator"
android:roundIcon="@mipmap/ic_launcher_2"
android:targetActivity=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
You have to add Multiple Alias for Laucher activity as many Icons you want to change. Like this.
val pm = packageManager
pm.setComponentEnabledSetting(
ComponentName(
this,
"com.photovideolocker.SplashActivity"
),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)
pm.setComponentEnabledSetting(
ComponentName(
this,
"com.photovideolocker.SplashActivityAlias1"
),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
pm.setComponentEnabledSetting(
ComponentName(
this,
"com.photovideolocker.SplashActivityAlias2"
),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
You can enable and disable the icon you want to set by this method.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论