Android——如何更改一项活动的标题栏文本?
This one is similar to a question that I asked yesterday. However my concern is different. To summarize I needed to remove the text from the titlebar for one of my activities (the main activity) (1). I did this using setTitle("");
on the onCreate
method. However when starting the application the former title remains displayed during 2 secs before changing to the new one.
It is probably because the titlebar is loaded before the activity loads, and I guess I either need to make the titlebar loads at the same time than when the activity loads or do this not in the code but in xml files.
Any idea?
Thanks!
(1): The reason why I want to do this is explained here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以从每个活动的清单文件中分别执行此操作。请查看此处。
You can do it from manifest file for each activity separately. Look here.
试试这个
@覆盖
public void onCreate(捆绑状态)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
您还可以尝试提供自己的标题布局
@覆盖
public void onCreate(捆绑状态)
{
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
Try this
@Override
public void onCreate(Bundle state)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
You can also try to supply your own title layout
@Override
public void onCreate(Bundle state)
{
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
如果您想以编程方式执行此操作,请在
onCreate
中使用setTitle();
例如,我有一个可用于两个目的的活动:添加新项目或将现有的编辑到数据库中。
在此示例
中,
editThis
是传入意图、数据或类似内容,指示我们要编辑现有项目。至于标题在几秒钟后发生变化。您是否为该活动设置了标题(例如在清单中)?应用程序很可能首先加载该信息,然后才继续执行您告诉它再次更改该信息的行。
If you want to do it programmatically use
setTitle();
inonCreate
For example, I have an activity that can be used for two purposes: either to add a new item or to edit an existing one to a database.
}
In this example
editThis
is an incoming intent, data or similar that indicates that we want to edit an existing item.As for the title changing after a few seconds. Do you have a title set for the activity, say in the Manifest? Chances are the app is loading that information first, only then to proceed to the line where you tell it to change that again.
转到您的值文件夹中的 strings.xml。在这里您可以看到 app_name 字符串。将该标签编辑为您想要的标签。
Go to your values folder, to strings.xml. Here you see app_name string. Edit that one to your desired label.