How to Change App Icon of Android Programmatically in Android? Last Updated : 16 Dec, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we are going to learn how to change the App Icon of an App on the Button Click. This feature can be used when we have an app for different types of users. Then as per the user type, we can change the App Icon Dynamically. Step by Step Implementation Step 1: Create a New Project To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language. Step 2: Add this in AndroidManifest.xml File XML <?xml version="1.0" encoding="UTF-8"?> <manifest package="com.prepare.packagename" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:theme="@style/Theme.packagename" android:supportsRtl="true" android:roundIcon="@mipmap/ic_launcher_round" android:label="@string/app_name" android:icon="@mipmap/ic_launcher_old" android:allowBackup="true"> <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=".MainActivityAlias" android:roundIcon="@drawable/ic_launcher_p_foreground" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" 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> </application> </manifest> Step 3: Working with the activity_main.xml file Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_gravity="center" android:gravity="center" tools:context=".MainActivity"> <TextView android:id="@+id/newicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" New Icon" android:textColor="@color/black" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/oldicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" Old Icon" android:textColor="@color/black" android:textSize="20sp" android:layout_marginTop="40dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </LinearLayout> Step 4: Working with the MainActivity.java file Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail. Java import android.content.ComponentName; import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Bundle; import android.text.SpannableString; import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.text.style.BackgroundColorSpan; import android.text.style.ClickableSpan; import android.text.style.ForegroundColorSpan; import android.view.View; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { TextView click, newicon; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); click = findViewById(R.id.oldicon); newicon = findViewById(R.id.newicon); click.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { changeicon(); } }); newicon.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { newicon(); } }); } private void changeicon() { // enable old icon PackageManager manager = getPackageManager(); manager.setComponentEnabledSetting( new ComponentName( MainActivity.this, "com.prepare.makedirectory.MainActivity"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); // disable new icon manager.setComponentEnabledSetting( new ComponentName( MainActivity.this, "com.prepare.makedirectory.MainActivityAlias"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); Toast .makeText(MainActivity.this, "Enable Old Icon", Toast.LENGTH_LONG) .show(); } private void newicon() { // disable old icon PackageManager manager = getPackageManager(); manager.setComponentEnabledSetting( new ComponentName( MainActivity.this, "com.prepare.makedirectory.MainActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); // enable new icon manager.setComponentEnabledSetting( new ComponentName( MainActivity.this, "com.prepare.makedirectory.MainActivityAlias"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); Toast .makeText(MainActivity.this, "Enable New Icon", Toast.LENGTH_LONG) .show(); } } Output: Comment More infoAdvertise with us Next Article How to Change App Icon of Android Programmatically in Android? A annianni Follow Improve Article Tags : Java Android Practice Tags : Java Similar Reads How to Change ActionBar Title Programmatically in Android? Whenever we develop an Android application and run it, we often observe that the application comes with an ActionBar with the name of the application in it. This happens by default unless explicitly changed. This text is called the title in the application. One can change the title of the applicatio 3 min read How to Fetch Device ID in Android Programmatically? The android Device ID is a unique code, string combinations of alphabets and numbers, given to every manufactured android device. This code is used to identify and track each android device present in the world. In Android, the Device ID is typically related to the Google Play Services and is most c 3 min read How to Change the Whole App Language in Android Programmatically? Android 7.0(API level 24) provides support for multilingual users, allowing the users to select multiple locales in the setting. A Locale object represents a specific geographical, political, or cultural region. Operations that require these Locale to perform a task are called locale-sensitive and u 5 min read How to Disable Dark Mode Programmatically in Android? In this article, we will learn how to disable Dark Mode programmatically in Android. Changing the theme of your app is a simple task that includes changing the code in the XML file. Step by Step Implementation Step 1: Create a New Project in Android Studio Create a new project by clicking on the fil 2 min read How to Set Background Drawable Programmatically in Android? In many android applications, we can get to see that the background color of this application changes dynamically when updated from the server. For updating this color we have to set the background color of our layout programmatically. In this article, we will take a look at How to Set Background Dr 3 min read How to Programmatically Enable/Disable Wi-Fi in Android? In Android Phone, it is very much easy to enable/disable WiFi by using the WiFi icon, but have you wondered how to do this task programmatically in Android. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project usin 3 min read How to Change the Screen Orientation Programmatically using a Button in Android? Generally, the screen orientation of any application is Portrait styled. But when it comes to gaming or any other multimedia service such as watching a video, the screen orientation must change functionally from Portrait to landscape or vice-versa when the functionality is not required. So a develop 3 min read How to Set an Image as Wallpaper Programmatically in Android? Setting wallpaper in Android programmatically is helpful when the application is fetching wallpapers from the API library and asking the user whether to set the wallpaper for the home screen or not. In this article, it's been discussed how to set a sample image as the home screen wallpaper programma 4 min read How to Programmatically Enable/Disable Bluetooth in Android? In Android Phone, it is very much easy to enable/disable Bluetooth by using the Bluetooth icon, but have you wondered how to do this task programmatically in Android. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this pr 3 min read How to Detect Tablet or Phone in Android Programmatically? A Mobile is a portable electronic device that allows you to make calls, send messages, and access the internet, among other functions. A tablet is a mobile computing device with a touchscreen display and typically a larger screen size than a smartphone. Both devices are designed to be portable and a 3 min read Like