我在用
Window w = getWindow();
w.setTitle("My title");
要更改我当前活动的标题,但似乎不工作。
有人能告诉我怎么改变吗?
我在用
Window w = getWindow();
w.setTitle("My title");
要更改我当前活动的标题,但似乎不工作。
有人能告诉我怎么改变吗?
当前回答
这对我很管用。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment, container, false);
getActivity().setTitle("My Title");
//...
}
其他回答
setTitle(“应用程序”); 在MainActivity.java中更简单 我会说。
如果你想要它一次,让系统处理剩下的(不是动态的),那么在你的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>
试试setTitle本身,像这样:
setTitle("Hello StackOverflow");
如果你正在使用onCreateOptionsMenu,你也可以在onCreateOptionsMenu中添加setTitle代码。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
setTitle("Neue Aktivität");
return true;
}
setTitle(getResources().getText(R.string.MyTitle));