David Shochet
David Shochet

Reputation: 5375

Application icon is not displayed in Xamarin.Forms Android app

I cannot figure out why my Xamarin.Forms Android app has the default robot icon.

Here is the structure I have now:

enter image description here

And here is what I have in "MainActivity.cs":

[Activity(Label = "My App Name", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

And here is what I have in "AndroidManifest.xml":

<application android:label="My App Name" android:icon="@mipmap/icon"></application>

And in "icon.xml":

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/launcher_background" />
    <foreground android:drawable="@mipmap/icon" />
</adaptive-icon>

Some solutions that I found online suggest moving the icons to the "drawable" folder, but I am not sure those solutions are up to date. I am using Visual Studio 2019.

Upvotes: 5

Views: 3335

Answers (1)

Leo Zhu
Leo Zhu

Reputation: 14956

mipmap-anydpi-v26 means for SDK 26 or greater, it uses the files in the folder of the XML file to use adaptive icons.

If your device version is lower than 26, you could check if the icon.png is stored in the folders correctly. If the version greater than or equal to 26, you could check the icon.xml.

By the way, the easiest way is put your icon.png into Resources/drawable folder, then use like:

[Activity(Label = "My App Name", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

Upvotes: 5

Related Questions