Android : Change App Label programmatically
Solution 1
It's not possible by the moment. It is a fixed string in the AndroidManifest.xml file which cannot be changed at runtime.
Solution 2
in the activity, i tried
this.setTitle("your text");
and it worked. I hope it's a common solution
Solution 3
Using <activity-alias>
you can change App icon and name to few predefined by you.
Create such config in Mannifest.xml
<activity android:name="package.name.MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/CustomTheme"
android:launchMode="singleTask">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias android:label="@string/app_name_default"
android:icon="@drawable/icon_default"
android:name=".MainActivity-Default"
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_flavor_one"
android:icon="@drawable/icon_flavor_one"
android:name=".MainActivity-Flavor-One"
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>
Now you can switch between those two aliases, therefore we will change app icon or/and name. To switch from Default to Flavor-One use this code.
getPackageManager().setComponentEnabledSetting(
new ComponentName("package.name", "package.name.MainActivity-Flavor-One"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
getPackageManager().setComponentEnabledSetting(
new ComponentName("package.name", "package.name.MainActivity-Default"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Keep in mind that you have to track that only one alias will be enabled at a time
Solution 4
In Launcher Activity,Before setContentView()
write this,
setTitle("Your Title");
I don't know how it's possible, But it's surely works.
Solution 5
Application's android:label is a fixed resource referrer.
But the string under this referrer could have multiple values, depending on configuration qualifier names (values-en, -large, -land, etc.), according to Providing Alternative Resources.
Soul
Updated on August 18, 2020Comments
-
Soul almost 4 years
How can I change application label to change app name shown from java code in android? I'm refering to:
<application android:icon="@drawable/icon" android:label="@string/app_name">
in the Android Manifest
Is there any way to update values in strings.xml file?