我在用
Window w = getWindow();
w.setTitle("My title");
要更改我当前活动的标题,但似乎不工作。
有人能告诉我怎么改变吗?
我在用
Window w = getWindow();
w.setTitle("My title");
要更改我当前活动的标题,但似乎不工作。
有人能告诉我怎么改变吗?
当前回答
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Main_Activity);
this.setTitle("Title name");
}
其他回答
如果你有多个活动,你可以在AndroidManifest.xml中这样设置
<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"
android:theme="@style/category_numbers" />
<activity
android:name=".FamilyActivity"
android:label="@string/category_family"
android:theme="@style/category_family" />
<activity
android:name=".ColorsActivity"
android:label="@string/category_colors"
android:theme="@style/category_colors" />
<activity
android:name=".PhrasesActivity"
android:label="@string/category_phrases"
android:theme="@style/category_phrases" />
<activity
android:name=".ExperimentActivity"
android:label="@string/category_experiment"
android:theme="@style/category_experiment" />
</application>
MainActivity内部:
public class act1 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act1);
setTitle("First Activity");
}
}
代码帮助我更改了标题。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_name);
ActivityName.this.setTitle("Your Activity Title");}
setTitle(“欢迎活动”);
试试setTitle本身,像这样:
setTitle("Hello StackOverflow");