Android——如何更改一项活动的标题栏文本?

发布于 2024-11-19 01:27:54 字数 612 浏览 7 评论 0原文

这个问题类似于问题< /a> 我昨天问过。然而我的担忧有所不同。总而言之,我需要从我的一项活动(主要活动)(1) 的标题栏中删除文本。我在 onCreate 方法上使用 setTitle(""); 来完成此操作。然而,启动应用程序时,前一个标题会在 2 秒内保持显示,然后才会更改为新标题。

这可能是因为标题栏是在活动加载之前加载的,我想我要么需要在活动加载的同时加载标题栏,要么不在代码中而是在 xml 文件中执行此操作。

有什么想法吗?

谢谢!

(1):解释了我想这样做的原因此处

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

睡美人的小仙女 2024-11-26 01:27:54

您可以从每个活动的清单文件中分别执行此操作。请查看此处

You can do it from manifest file for each activity separately. Look here.

青巷忧颜 2024-11-26 01:27:54

试试这个

@覆盖

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);

夏末的微笑 2024-11-26 01:27:54

如果您想以编程方式执行此操作,请在 onCreate 中使用 setTitle();

例如,我有一个可用于两个目的的活动:添加新项目或将现有的编辑到数据库中。

if (editThis == null) {
    setTitle(getString(R.string.new_item)); //set activity title to new
        } else {
    setTitle(getString(R.string.edit_item)); // set Editor title to edit

在此示例

中,editThis 是传入意图、数据或类似内容,指示我们要编辑现有项目。

至于标题在几秒钟后发生变化。您是否为该活动设置了标题(例如在清单中)?应用程序很可能首先加载该信息,然后才继续执行您告诉它再次更改该信息的行。

If you want to do it programmatically use setTitle(); in onCreate

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.

if (editThis == null) {
    setTitle(getString(R.string.new_item)); //set activity title to new
        } else {
    setTitle(getString(R.string.edit_item)); // set Editor title to edit

}

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.

撧情箌佬 2024-11-26 01:27:54

转到您的值文件夹中的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文