[英]Activity android:label change application name
我開始了一個沒有活動的新項目,然后我創建了自己的項目並注冊它們以顯示如下。 但是只要我在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>
在application
標記中添加android:label="app name"
在application
標記中使用android:label
將設置應用程序名稱。 而使用android:label
在Activity
標簽將設置標題Activity
。
從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");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.