Activity android:label 更改应用程序名称

Activity android:label change application name

我开始了一个没有 activity 的新项目,然后我创建了自己的项目并注册它们以如下所示显示。但是每当我在我的 LoginActivity 上放置一个标签时它就会接缝,它会更改应用程序名称。

<application
    android:name=".app.ApplicationController"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".activities.LoginActivity"
        android:label="@string/login_screen_label"
        android:launchMode="singleTop"
        android:windowSoftInputMode="adjustPan">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".activities.RegisterActivity"
        android:launchMode="singleTop"
        android:windowSoftInputMode="adjustPan" />
    <activity
        android:name=".activities.MainActivity"
        android:launchMode="singleTop"/>

</application>

还有我的字符串资源

<string name="app_name">My ToDo</string>
<string name="login_screen_label">Log in</string>

我做错了什么

更新actitity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="0dp" >

</RelativeLayout>

从 mainfests 中删除这一行

android:label="@string/login_screen_label"
Toolbar toolBar = (Toolbar) findViewById(R.id.toolbar_actionbar);   
toolbar.setTitle(your label);

如果您将 AppTheme 与像 DarkActionbar 这样的 Actionbar 一起使用,那么您需要设置工具栏并在工具栏中设置标题,如上所示

您可以在 onCreate()

中使用以下代码
getSupportActionBar().setTitle("My title");

完整代码:

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
    getSupportActionBar().setTitle("My title");

  }
}

application 标签中添加 android:label="app name"

application 标签中使用 android:label 将设置应用程序名称。在 Activity 标签中使用 android:label 将设置 Activity.

的标题