gpt4 book ai didi

AndroidManifest中的android:label问题(无法设置标题)

转载 作者:行者123 更新时间:2023-11-30 04:54:26 27 4
gpt4 key购买 nike

当我尝试在 AndroidManifest.xml 中为每个 Activity 提供不同的标题时,应用会显示所有子 Activity 的第一个标题,而不是给定的标题。我是编码新手,很抱歉对我的问题的错误解释。代码如下:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.miwok">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NumbersActivity"
android:label="@string/category_numbers" />
<activity
android:name=".FamilyActivity"
android:label="@string/category_family" />
<activity
android:name=".ColorsActivity"
android:label="@string/category_colors" />
<activity
android:name=".PhrasesActivity"
android:label="@string/category_phrases" />
</application>

</manifest>

我该如何解决?

更新:为了更清楚,我添加了我的 MainActivity 代码:

 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
TextView numbers = (TextView) findViewById(R.id.numbers);
TextView colors = (TextView) findViewById(R.id.colors);
TextView family = (TextView) findViewById(R.id.family);
TextView phrases = (TextView) findViewById(R.id.phrases);

assert numbers != null;
numbers.setOnClickListener(this);
assert colors != null;
colors.setOnClickListener(this);
assert family != null;
family.setOnClickListener(this);
assert phrases != null;
phrases.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.numbers:
Intent numberIntent = new Intent(MainActivity.this,NumbersActivity.class);
startActivity(numberIntent);
break;
case R.id.colors:
Intent colorsIntent = new Intent(MainActivity.this,NumbersActivity.class);
startActivity(colorsIntent);
break;
case R.id.family:
Intent familyIntent = new Intent(MainActivity.this,NumbersActivity.class);
startActivity(familyIntent);
break;
case R.id.phrases:
Intent phrasesIntent = new Intent(MainActivity.this,NumbersActivity.class);
startActivity(phrasesIntent);
break;
}

}
}

第二次更新:当我为每个 Activity 复制 Intents 时,我忘记更改 Activity 名称,所以问题不在标题中,而是在打开的 Activity 中。

最佳答案

您可以在代码中命名它:通过

actionbar.setTitle("title here");

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!MyApplication.getInstance().isTablet())
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_settings);

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getString(R.string.settings));

....
}

关于AndroidManifest中的android:label问题(无法设置标题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59481873/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com