如何在Xamarin.Forms中更改Android应用程序名称?

29

我正在使用Visual Studio for Mac中的Xamarin.Forms开发,并创建了一个非常基本的Xamarin.Forms应用程序。

我已经检查了Android和iOS目标。 我有3个项目:

  • 一个共同的项目
  • 一个特定于iOS的项目
  • 以及一个特定于Droid的项目。

Android特定的应用程序在应用程序名称中具有“.Droid”后缀。

所以我决定右键单击droid项目,并在“程序集名称”字段中删除此后缀。

当我运行该应用程序(在启动时)时,我遇到了异常。 如果我再次更改程序集名称以放置droid后缀,则不再起作用。

您可以尝试使用最新版本的Xamarin.Forms中的空白项目进行此操作。

我不明白为什么会这样?

4个回答

77
The problem is that you are changing the assembly name of your application, not the name.
If you want to change the application name in Xamarin.Forms Android, you have two options:
- Go to your MainActivity and change the Label property.

enter image description here

  • 或者,可以移除MainActivityLabel,并通过UI或代码在Manifest.xml中添加名称:

enter image description here enter image description here


在iOS上,您必须在Info.plist中更改它。

enter image description here


我在 Manifest.xml 文件中只有“myappname”。我不明白为什么在应用图标下看到了“.Droid”后缀。 - Bob5421
实际上,我在空白表单应用程序项目模板方面遇到了问题。我使用Xamarin for Mac工作。 - Bob5421
Visual Studio for Mac - Bob5421
请清除旧评论,这样我们就不会在这里有很多文字。这对未来的用户更好。我已经更新了我的答案,请阅读它。 - jzeferino
注:如果您有一个启动画面活动,似乎您也需要更改 [Activity(label = "Your new App Name".... 希望这可以帮到您。 - John Irvine

14

其他回答已经很好了。

但我要添加更多细节。

应用程序名称是从AndroidManifest.xml文件中选择的,即<application android:label=@string/app_name,该文件又引用了values>strings.xml文件。不要在此处硬编码应用程序名称。把所有在strings.xml文件中使用的字符串分离出来是一个好习惯。

应用程序名称图片

strings.xml

<resources>
  <string name="app_name">App Name</string>
</resources>

Label属性覆盖并将应用程序标题、apk名称设置为MainActivity内设置的标签值。

最好从MainActivity.cs的程序集指令[Activity中删除Label值(因为它会在调试时覆盖清单值),并在strings.xml中更改值,以使其全局和一致。

Image 2


2

对于Android,请在Android文件夹中的MainActivity.cs文件中进行更改。

[Activity(Label = "Myappname", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

Fos iOS

在info.plist中进行以下更改:

Bundle display name 更改为 Myappname


1
   //Change the Xamarin Forms Android Application Name

   [Activity(Label = "ApplicationName", Icon = "@mipmap/icon", Theme = 
   "@style/splashscreen", LaunchMode = LaunchMode.SingleTop, MainLauncher = true, 
    ScreenOrientation = ScreenOrientation.Portrait,ConfigurationChanges = 
    ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | 
   ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]



  //In IOS , we can change the name of Application in info.plist
                 
                 Double click in info.plist , change Application Name

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接