You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Xamarin Android中设置不同的应用启动名与页面标题?

Fix: Separate Launcher App Name from Activity Page Title

Alright, let's tackle this label conflict you're dealing with—where your launcher shows "Demo App" but you want it to display "MyApp", while keeping the activity's page title as "Demo App". Here's how to fix it step by step:

What's Causing the Issue

Android uses the main Activity's Label attribute as the launcher icon's display name by default, even if you've set an app-level label in AndroidManifest.xml or AssemblyInfo.cs. That's why your launcher shows "Demo App" (from MainActivity.cs) but Gmail sees "MyApp" (from the app-level config).

The Solution: Split Label Configurations

We'll separate the launcher's app name (controlled by the app-level settings) from the activity's page title (set dynamically in code). Here's what to change:

1. Update AndroidManifest.xml

Make sure your app-level android:label (for launcher name) and android:icon are properly set—this is what the launcher will use:

<manifest> 
    <application android:label="@string/app_name" android:icon="@drawable/AppIcon"/> 
</manifest>

2. Add a Dedicated String for Activity Title

In String.xml, add a new string resource to use as the activity's page title, so we don't mix it up with the app name:

<string name="app_name">MyApp</string>
<string name="home_activity_title">Demo App</string>

3. Adjust MainActivity.cs

Remove the Label property from the Activity attribute—we'll set the page title via the ActionBar instead. This way, the launcher won't pick up the activity's label anymore:

[Activity(MainLauncher = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.main);
        
        // Set the ActionBar's icon and page title
        ActionBar.SetIcon(Resource.Drawable.Icon);
        ActionBar.SetTitle(Resource.String.home_activity_title);
    }
}

Why This Works

  • The launcher now reads the app-level android:label (MyApp) as the icon's display name
  • We're setting the activity's page title dynamically through the ActionBar, so it shows "Demo App" once the app opens

After these changes, you'll see "MyApp" in Gmail and on the launcher, while the app's main page will have "Demo App" as its title—exactly what you wanted!

内容的提问来源于stack exchange,提问作者Anish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:50:59