Xamarin.Android: Problems changing the application icon from the default icon - c#

I just started learning how to develop for Android a few days ago, so I'm still in the process of learning all the ins and out of the environment. Recently, I finished writing the functionality for a basic Contacts app and decided to turn to fixing some of the finer points of the UI. I have been trying for the last couple of days to change the launcher icon for the app from the default Android icon Default Icon to one that I selected Selected Icon. However, nothing I seem to try will allow the icon I selected to appear on the device I am testing on.
I added what is supposed to be the proper line in the Android Manifest file as seen here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="Contact_Manager.Contact_Manager" android:versionCode="1" android:versionName="1.0" android:installLocation="internalOnly">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:label="Contacts" android:icon ="#drawable/contacts-3"></application></manifest>
But this solution did not work. I also tried deleting the default icon from the drawable folder(I also saved a copy of it elsewhere) but it still showed the default Icon on the device screen. I then tried to uninstall the application on the device in order to clear all the cache files, but was met with the same outcome. Is there something I'm doing wrong?
Note: I am also new to StackOverFlow so I apologize if the formatting of this question is awful.

I suspect you have not deleted all the versions of default icon. In android there is a icon for each screen density in drawable-mdpi, drawable-hdpi, etc folder. Hence search for that file and remove it from all the folders and try again.
You need to add fresh icons for each density.
UPDATE 1 :
I think I know the problem now. Right click the project on solution explorer. Then click on options. Then Build-Android Application.
Change the application icon there.

Delete the default icon.png files from all the Android drawable folders, and save your new icon as icon.png. Also make sure that in the manifest you point to the icon file:
<application android:label="<Your app name>" android:icon="#drawable/icon"></application>

Try with a different icon name
Copy the new icon(myIcon.png) into mipmap- folders.
Update the icon value in Android project MainActivity.cs file
Uninstall the application from your device and try again.

Had the same issue. Deleted the old icons (maybe you only removed them from project not deleted them? I dont know) and tried building. It threw errors wherever the old icon was referenced so I was able to trace the issue. Also removing the old and adding the new with the same name (Icon.png) worked for me

Related

How to add icon to wpf Application in Visual Studio Code

I am trying to add file.ico to my WPF Application. I know that in Visual Studio it's easier, however I am confused about how to add it in Visual Studio Code. So Basically I want to add the file.ico in the project folder such that the app also works on other computers.
Note: it works when I add the full path in the MainWindow.xaml ( Icon="Path\file.ico" ), but instead I want to write just Icon="file.ico" (the file.ico can also be in a folder in the project). I know that I need to add resources in the App.xaml and Project.csproj , but I don't know how.
WPF is a relatively new topic for me and I would appreciate any help.
Thanks in advance
I have found a solution, which is pretty simple: add this code to .csproj file
<ItemGroup>
<Folder Include="Assets\" />
<Resource Include="Assets/file.ico" />
</ItemGroup>
and then added this code to MainWindow.xaml file: Icon="/Assets/file.ico"
I've seen a number of approaches to this problem that suggest using NotifyIcon from Windows.Forms to instantiate and show the icon. This overly complex. The good news is there is no need for this in WPF. It is extremely simple to add the application icon in WPF using Visual Studio.
Right click on the top level project folder in the solution explorer and go to properties.
The application properties window opens.
Click on Win32 Resources. Browse for the icon file in your project. Images of type .png or .jpg won't work. Google "png to ico" and you can get the ico file for free. Close the application properties window. Your done.
You will now see the icon in the System Tray and in the upper left corner of each window (if you use a variation of the default window style).
Right click on your solution and click: Add > New folder. You can call it whatever you want for example 'Assets'. Right click on that folder and click add existing item. Make sure to change the file type to All files. Navigate over to your icon file and double click it. When it's imported click on it and make sure Build action is set to 'Content'.
You can also use .png images for your icon

C# Couldn't process file xxx.resx due to its being in the Internet or Restricted zone or having the mark of the web on the file

I have an issue while I try to build project in VS2012.
It cannot build due to the error:
Couldn't process file xxx.resx due to its being in the Internet or Restricted
zone or having the mark of the web on the file. Remove the mark of the web if
you want to process these files.
Here is a similar question.
but I tried that option and had no luck, because I did not download the file from the internet. That project was built from scratch. In project after selecting Properties, in Windows Explorer nothing happened. I do not have the "unblock" option, only the default three options (read only, hidden, and archived).
I have the same error and cannot build or rebuild the project. I have a theory that it is a recent error after updating Windows. Before the update, everything worked fine. Any ideas?
Go to xxx.resx file in Windows File Explorer. Right-click and select properties. At the bottom of the the dialog is an "unblock" option:
Check this and click Apply. Clean your solution and it will build.
In my case I had the same problem with many files.
My solution with VS Prof. 2017 V15.95 was:
Open powershell and execute dir -Path [directory path] -Recurse | Unblock-File
Rebuild all
On the solution folders locate abc.resx.
Open the file using any text editor, preferably Notepad++.
Locate and delete any node starting with <data
Example. This is what you should delete.
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAMAICAAAAEAIACoEAAANgAAAGBgAAABACAAqJQAAN4QAACAgAAAAQAgACgIAQCGpQAAKAAAACAA
AABAAAAAAQAgAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
///////////8AAB/////////
</value>
</data>
Reload or reopen your solution and build. You are ready to go.
Had the same problem after updating to VS 2017 v15.8.5, and none of the solutions above or on other forums worked for me.
So, since a .resx file is just XML, I just copied the content, deleted the original file and recreated it with the copied content.
That was the only thing that worked, and it worked first time.
A quick way to remove this mark of the web for multiple files and folders recursively for me was to
Zip them up.
Delete originals.
Unzip.
I'm not really sure either, I have the exact same issue.
But, what i did, was hit view in file explorer.
Then, i clicked show hidden items.
Finally, i went back to my folder and clicked on the .vs folder, my project/file name, v15, Server, sqlite3, and deleted DB.Lock.
I reopened the project, clicked build, and it worked perfectly.
This worked for me, it might/might not for you.
I also encountered this issue recently. The error began occurring after I set the icon of a Windows Form.
Researching for the cause and solution almost led me nowhere, because I did not download the icon from the internet, nor was I referencing a web-based icon file. It was stored entirely on my local machine.
After some more researching and digging around, I was able to figure out exactly what was causing the problem. I have Microsoft One-Drive installed on my machine. The directory in which the icon file was located is managed/synced by One-Drive. That fact was somehow tricking Visual Studio into believing the file was located or downloaded from the internet.
The solution proved to be very simple. I removed the icon from the form, as well as from the corresponding .resx file. Then I moved the icon file to another directory not associated with One-Drive. Finally, I was able to use that icon in my Windows Forms application without getting this error.
I understand there are other possible causes for this error. But if in your case, the issue happened after setting a form's icon--and if you have One-Drive (or perhaps another cloud-based storage solution) installed--then check to be sure that icon file is not in a directory managed by that service. If so, relocate it and change the form's icon property to point to the new location.
To fix this for multiple files within a project, Visual Studio -> Tools -> Options -> Trust Settings and add the project path as a trusted path.
Using VS 2019, and building against source stored on an Azure shared file system. I think I may have just tracked down a work-around, and it has to do with the Icon as referenced above by Jake above. If I add the icon to the form's resource file (that really long string), The error occurs.
However, if I add the Icon to the Project's resources, delete the Icon from the form's resource file, and change form to set the Icon manually...
this.Icon = MyProjectName.Properties.Resources.MyIcon;
The error goes away.
I found this solution on another forum. My project resided on a file share, so I had to enter file://[file share] for Step 4 below. I am running VS2019 on Windows 10.
Start Menu > type 'Internet Options'.
Select Local intranet zone on the Security tab then click the Sites button
Click Advanced button
Enter file://[computer name] or file://[file share]
Make sure 'Require server verification...' is unticked
I had the same issue in Windows 10 VS 2019 16.4.457 (previous version of VS 2019 had no problems).
The "marked for web" error shows only after I moved the project under One-Drive.
If I move the project back to a local drive the error doesn't show.
As Anthony Gingrich suggested, I tried to move the project images to a local directory without success.
The solution that works for me was, for each image, in the "Select Resource dialog" use "Project resource file" instead "Local resouce".
Please guys, I already fixed the issue, this is cause by OneDrive, please close your OneDrive with the use of task manager or close the icon OneDrive's Hidden Icons on the taskbar
I just ran into the same issue and also tried the Unblock option from explorer with no luck. I even restarted VS with no luck.
However, I'm not sure which combination did the trick but I opened the form as well as the resx file from within VS, just to see if I can open it, which opened fine. I then did a clean and rebuild and that appeared to do the trick. If it doesn't try restarting VS after the clean then rebuild.
I had a similar issue and the problem was an image that I had downloaded and added to my Resources. Not completely sure why that was the only image that gave me problems, however, I opened my abc.resx file giving me issues an a text editor, removed the node starting with " (it was the last and only node) just like Albert Alberto mentioned. Saved the changed, cleaned and rebuilt my solution and it all works! The image didn't render but it only took a second to go back and add the image. It wasn't removing the entire file, just the node that was causing the issue.
I had the same problem on Windows 10, VS 2017 (15.9.13). I sent myself a project from work through Dropbox so I could try a couple of things from home. But when I tried to build it VS gave me the 'marked for web' error.
After trying the solutions above without success I began experimenting. I was able to solve this by using the method listed above (right click -> properties -> unblock), but I had to do it for each of the images in the Resource folder--and I had to do EACH FILE individually since the 'unblock' option was not available on group-selects. I actually unblocked each source file in the project as well before trying to rebuild so I am not sure if both are required.
Its a bit of a pain--probably a huge pain for larger projects--but it absolutely got the project building again.
EDIT: I did find this article afterwards about unblocking entire folders--even recursively but have not tried it: https://www.winhelponline.com/blog/bulk-unblock-files-downloaded-internet/
None of these worked for me. I fixed it by converting the embedded base64 into a linked resource:
I found out the issue was with the embedded base64 image I had in the .resx (as the issue went away removing the data tag as explained in this question but that meant I removed the image) so I converted the embedded image into a .png file and made a link to that in the .resx.
To do that: open the .resx file in Visual Studio 2019 and double-click the image, and then click Ok and Yes in the following prompts that will appear so VS will convert the embedded image into a linked resource (sorry I can't upload pictures yet):
Hope it helps!
From my original comment.

Non-existing icon generated in manifest

I created a project with a template that included a launcher icon called Icon. I received the right one to use so I changed it, and named it ic_launcher.
I changed the name on the manifest:
android:icon="#drawable/ic_launcher"
And in the launcher activity annotation:
[Activity(Label = "[...]", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, Icon = "#drawable/ic_launcher")]
When I build the project, the IDE generates a complete AndroidManifest (located at \obj\Debug\android\manifest\AndroidManifest.xml) that contains the right icon names, except for this line:
<activity android:configChanges="[...]" android:icon="#drawable/icon" android:theme="[...]" android:name="[...]" />
Which says; android:icon="#drawable/icon". I searched the text in the project and found nothing.
The file is generated in every build, so no matter what I try, it's always changed back and thus, I can't deploy.
Any ideas?
Yes, I know I can just rename ic_launcher to Icon but I want to try to do the right thing first.
Thanks.
Android by default takes up 'ic_launcher' drawable which is an Android Logo. Trying changing the name to something different like 'app_logo' and try refreshing/Cleaning and rebuilding the project.
UPDATE:
As the change of name doesn't work yet, follow these steps.
Uninstall the app completely and try building and installing.
Make sure the icon with the other name say 'app_name' is placed in all density folders.
Ensure that you don't have an Icon Activity definition in your Main Activity because this overrides the manifest. It a very common situation.
More info on this here
Hope this helps.
After an internal talk, it turns out a library was generating that activity declaration. That definition was then added to the manifest of the project and causing the issue.

Why images in drawable folder are not showing in my Android compilation of Xamarin.Forms?

I try to compile my Xamarin.Forms app and the images in the drawable folder can´t be loaded... The screen shows all the elements except images or icons.
I also get the error that says "obj/bin/debug/packaged_resources" doesn´t exist... It seems that this file is not being generated. I´m temporally avoiding this error by copy-pasting this file from another version of the app in my version control, but like I said before, images are not showing.
I have also checked the correct name of the image files to be compatible.
I have tried lots of purposes in Xamarin forums and cannot solve the problem. Any help would be appreciated. Thanks.
Please add the file with the help of "Add file" context not copying directly or dragging in to the resource folder..
Also rebuild the project after adding those image files..
I had the same issue. If you exclude image in one of the drawable folder and then include then it become visible in preview as well.

Why does the desktop icon differ from the explorer icon?

For some reason, a very old version of my icon keeps showing up when my application is dropped on the desktop. In the windows explorer (in all zooming levels) the icons is correctly the assembly icon. I specified the correct item in both XAML Window.Icon and in the project settings.
I have deleted the old version of my icon from all folders I can think of, but it still shows up. Also while drag and dropping, the wrong icon is shown. (in the slightly transparent preview window)
I tried cleaning and rebuilding, I tried deleting the obj folder manually...
The original, wrong icon was 16x16. I have built the new version as 32x32, because on the desktop 16x16 is too small.
According to the msdn docs (http://msdn.microsoft.com/en-us/library/system.windows.window.icon.aspx), each .ico file is supposed to incorporate all smaller sizes anyway.
I also checked that I changed the icon for both debug and release configuration.
Thanks for any ideas! :)
Could this be a problem with the IconCache? Try deleting %localappdata%\IconCache.db and restarting Explorer.exe.
Check the Visual Studio properties window for the EXE's project -- you can specify the icon that's written into the EXE at compile time. This is separate from the icon that's assigned to the XAML window at run time.

Categories