How can I change the launcher icon and its label from my application runtime in Android? (if it is possible)
I mean the properties defined in AndroidManifest.xml: android:icon and android:label. I want to replace it by the image I take from the camera.
This entire answer is from this post and it was taken from P-A and CommonsWare.
You cannot change the manifest or the resource in the signed-and-sealed APK, except through a software upgrade. or
Try this, it`s work fine for me but not sure for all devices:
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>
Create <activity-alias> for your app, for each of your icons. Like this
<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>
Set programmatically ENABLE attribute for necessary
getPackageManager().setComponentEnabledSetting(
new ComponentName("ru.quickmessage.pa", "ru.quickmessage.pa.MainActivity-Red"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Note, At least one must be enabled and above code perfect working up to 4.0 not tested into >4.0.
Edit: your original answer didn't specify you wanted to do it at runtime. Below the line is how to do it before it compiles. As for doing it programmatically at runtime:
From this answer:
You cannot change the manifest or the resource in the signed-and-sealed APK, except through a software upgrade.
But also, the accepted answer figured out a "hack" or some cheating way to do it (I presume). I haven't tested it, but there is a source for you to check out.
Or, this link apparently describes how to do this using the "widget" approach.
So lets say your manifest was like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="yourPackage"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
...
You would change the launcher icon by putting images into your drawable folders:
Project folder --> res --> all the drawables
Then you would change the android:icon="#drawable/ic_launcher" to be android:icon="#drawable/whateverTheNameOfTheImageIsYouPutInTheDrawablesFolders"
To change the label:
Open up your strings.xml file which is located:
Project folder --> res --> values --> strings.xml
And look for the string that looks like this:
<string name="app_name">Your App Name</string>
And just change Your App Name to be whatever you want the label to be.
Summary:
android:icon="#drawable/ic_launcher" determines your launcher icon, so just add images to the drawable folders and change ic_launcher to whatever the name of image is that you want to be the icon.
android:label="#string/app_name" determines your "label" so just look for app_name (because the label is referenced to #string/app_name) in your strings.xml file and change the contents of app_name.
Related
I'm trying to add a launcher icon to my android app. I have watched multiple tutorials online that explain how that works. I ended up doing it this way:
https://www.youtube.com/watch?v=DQ8HDL-X9rM
The laucher icon does appears in the android simulator but not on physical phones.
what I have tried to do:
clean the build in android studio
reset the icon the way it says in the tutorial
checked the reference in android manifest
checked if the icon was changed in the drawable and mipmap folders
that were the tips that showed up in a stackoverflow topic a couple years back.
I have been working on it for the passed week and I just can't get it to work.
This is my ic_launcher.xml
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#color/ic_launcher_background"/>
<foreground android:drawable="#mipmap/ic_launcher"/>
</adaptive-icon>
And this is this are the lines in my AndroidManifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
<activity android:name="com.example.fragments.Product">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.MainActivity" />
</activity>
<activity android:name="com.example.MainActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
Also I checked all the mipmap folders and all my icons are in there with the correct names.
Does anyone know what I can do?
---update june 3---
Now its not even showing up on the emulator anymore...
I have tried and read all the topics online I really hope someone can spot what I do wrong
You can simple way to add icon for app
go to project
app->res->drawable->right click->new->image asset-> source asset
select image path and click to next button
RUN the app
another way
I know how to change the icon of my app, but when I look at the Recents Screen, the icon is the default one.
App icon (all good so far):
Icon in my Recents Screen:
This is the 'application' tag of my 'AndroidManifest.xml'
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/iconout"
android:roundIcon="#mipmap/iconout"
android:logo="#mipmap/iconout"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
I've tried many solutions that I found on this platorm (that didn't work), like:
file->new->image asset->choose image..
install & unistall the app
build & clean project
delete all the default icons on my project
drag & drop my icon to drawable from mipmap folder
Any other possible solutions? Thank you in advance!
Ok I found the solution and decided to answer for anyone that will encounter the same problem in the future.
I fixed it by adding android:icon="#mipmap/iconout" in the main activity tag declaration in the AndroidManifest.xml, like so:
<activity
android:icon="#mipmap/iconout"
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And here's the final result:
Try to change the format of the icon to PNG. That works for me.
Or you could try the application on different devices to see if it's not a problem of the emulator/phone.
I've got a simple application with one single activity. Actually, the launcher icon is the same as the activity's one (the one in the top-left corner). I would like to put another icon in my activity without changing the launchers'one.
Here is my manifest :
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.natinusala.pebkac.MainActivity"
android:label="#string/app_name">
<intent-filter android:logo="#drawable/pebkac">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Actually, I can edit the launcher and activity icon by editing the android:icon="#drawable/ic_launcher" line. I can do it also in adding an android:icon into the <activity> but it modify too the launcher's icon.
How can I do to edit my activity's icon without touching the launcher's one ?
Thanks !
In your manifest, add android:logo="#drawable/ic_yourIcon" to either your Activity or Application tag.
I am simply trying to change the background color for an activity, however nothing has changed.
Here is the relevant XML:
styles.xml
<resources>
<style name="STBTheme" parent="android:Theme.Light" >
<item name="android:windowBackground">#color/blue</item>
</style>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pedro.stb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/STBTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/STBTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Furthermore, I'm using Eclipse, and by changing the theme in the activity's xml, it does not change in the graphical layout.
Any help?
Edit
Got it to work. Have to clean the project before reloading the layout. Very annoying...
i had check your code its ok .
try <item name="android:Background">#ccff33</item>
instead of your <item name="android:windowBackground">#color/blue</item>.
and you have write android:theme="#style/STBTheme" > in application as well as activity also.
Just write in application tag .
Hope you will get your output now.
Open the preview of your activity and Click on the circled button as shown
Type the name of your custom theme and Click 'OK' as shown
In Manifest file add the attribute android:theme=".YourTheme" to the required Activity
You will have the theme of the current activity changed.
I dont know why Android Studio acts like it's drunk sometimes. I have two projects with same target,minimum SDK active. One of them had the splash screen theme implemented correctly, the other just wont show until I found this workaround.
As mentioned in the title, my launcher icon is showing up fine on the emulator, but the default icon was shown on my phone.
Here's my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ytz.bc"
android:versionCode="1"
android:versionName="1.0a" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ProjectBriefcaseActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Most likely, you have replaced the default icon with your icon only in one of the drawable folders, and coincidentally the emulator is using the folder, while your device is using one of the other folders. See this link for icon design guidelines, and this one for the recommended size.
Can you post what's there in all your drawable folders?
You might have done this thing: replaced the ic_launcher.png file in drawable-mdpi folder with another image(your launcher icon) and named it ic_launcher.png .
You actually do not need to rename the file icon file you out in the drawable folder, but you need to change the android manifest to tell the application which file to use as the launcher icon.
Suppose if i put launcher_icon.png in the drawable-mdpi folder, and i want that to be my launcher icon, i will change the manifest to this:
<application
android:icon="#drawable/launcher_icon"
android:label="#string/app_name" >
I changed the tag
android:icon="#drawable/ic_launcher"
to
android:icon="#drawable/launcher_icon"
paste your launcher image and do the change according to the file name of that image...
If you have placed your icons correctly, still you don't see the icon change then, go to Project->Clean....
In res folder inside bin you will find all your resouce items. You can check before cleaning the project and you will find that you have the old ic_launcher file. If you clean the project, these folders will be deleted. When you run your application again a new set of files will be copied and your application icon will be changed.
Hope this helps.
Note: This will work only when you have replaced the icons in all the folders still you are getting the old icon.