[转] Android 在程序中如何动态的修改程序图标
http://stackoverflow.com/a/41501402
亲测可以!
测试机器环境如下:
MeizuMx4-Android5.1-Flyme5.1.11.1A
Firstprepareyournewappiconsforeachresolutionandputthemintothecorrespondingmipmapfolders.
Then use activity-alias, for example, in your AndroidManifest.xml, edit this:<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity-alias android:name=".MainAliasActivity" android:enabled="false" android:icon="@mipmap/ic_launcher_fight" android:label="Main Alias Activity" android:targetActivity=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity-alias>Add the following code when you want to change your app icon
PackageManager pm = getPackageManager(); pm.setComponentEnabledSetting( getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); pm.setComponentEnabledSetting( new ComponentName(this, "YOUR PACKAGE.MainAliasActivity"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);To reset the app icon you can use the same way.
Github:https://github.com/chinglimchan/ChangeAppIcon
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28