Skip to content

Instantly share code, notes, and snippets.

@z8888q
Last active July 11, 2022 07:26
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save z8888q/7280681 to your computer and use it in GitHub Desktop.
Save z8888q/7280681 to your computer and use it in GitHub Desktop.
How to change an application icon programmatically in Android
//1 . Modify your MainActivity section in AndroidManifest.xml, delete from it, line with MAIN category in intent-//filter section
<activity android:name="ru.quickmessage.pa.MainActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/CustomTheme"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />//DELETE THIS LINE
</intent-filter>
</activity>
<activity-alias android:label="@string/app_name"
android:icon="@drawable/icon"
android:name=".MainActivity-Red"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
getPackageManager().setComponentEnabledSetting(
new ComponentName("ru.quickmessage.pa", "ru.quickmessage.pa.MainActivity-Red"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
//不显示icon的代码如下
getPackageManager().setComponentEnabledSetting(
getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
//here is superuser.apk code
<activity android:theme="@style/Theme.Sherlock.Light" android:label="@string/app_name" android:icon="@drawable/transparent" android:name=".MainActivity" android:exported="true" android:excludeFromRecents="true" android:launchMode="singleTask" android:configChanges="locale|keyboard|keyboardHidden|orientation|screenLayout" android:noHistory="false" android:hardwareAccelerated="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_emblem" android:name=".MainActivity-Emblem" android:enabled="true" android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_superandy" android:name=".MainActivity-SuperAndy" android:enabled="false" android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_original" android:name=".MainActivity-Original" android:enabled="false" android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_chip" android:name=".MainActivity-Chip" android:enabled="false" android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="@string/app_name" android:icon="@drawable/ic_launcher_supersu" android:name=".MainActivity-SuperSU" android:enabled="false" android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
@bigshotchina
Copy link

When component has been disabled, the app widget on launcher will be deleted also.

@prashantchau
Copy link

I want to simply change application icon from main activity.tell me code which is required in activity and in manifest file.

@gomathi14
Copy link

I want to simply change application icon from main activity.tell me code which is required in activity and in manifest file.

@pavanbol
Copy link

is it possible to change app icon without closing the application , as in my app we need to change app icon after user launched his application , so can I change app icon with closing it , as closing kind of feels weird just after login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment