Application icon is not displayed in Xamarin.Forms Android app

不羁岁月 提交于 2020-06-26 06:28:27

问题


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

Here is the structure I have now:

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. Please advise.


回答1:


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


来源:https://stackoverflow.com/questions/58613457/application-icon-is-not-displayed-in-xamarin-forms-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!