我在用
Window w = getWindow();
w.setTitle("My title");
要更改我当前活动的标题,但似乎不工作。
有人能告诉我怎么改变吗?
我在用
Window w = getWindow();
w.setTitle("My title");
要更改我当前活动的标题,但似乎不工作。
有人能告诉我怎么改变吗?
当前回答
试试setTitle本身,像这样:
setTitle("Hello StackOverflow");
其他回答
试试setTitle本身,像这样:
setTitle("Hello StackOverflow");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Main_Activity);
this.setTitle("Title name");
}
如果你想要它一次,让系统处理剩下的(不是动态的),那么在你的manifest文件中这样做:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name_full" > //This is my custom title name on activity. <- The question is about this one.
<intent-filter android:label="@string/app_launcher_name" > //This is my custom Icon title name (launcher name that you see in android apps/homescreen)
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我使用的是Android Studio 3.0.1。
有一个活动:
setTitle("Title Text");
在一个片段内:
getActivity().setTitle("Title Text");
如果你想在Java文件中设置标题,那么写在你的活动onCreate
setTitle("Your Title");
如果你想在Manifest里写
<activity
android:name=".MainActivity"
android:label="Your Title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>