gpt4 book ai didi

android - 方法 setTitle 的工具栏错误

转载 作者:行者123 更新时间:2023-11-29 20:47:10 27 4
gpt4 key购买 nike

我在我的工具栏中使用了这两种方法:

    toolbar.setTitleTextColor(getResources().getColor(R.color.ColorPrimary));
getSupportActionBar().setTitle("title");

使用 getSupportActionBar 的原因是因为 toolbar.setTitle("title"); 不起作用。

这是一个错误?

最佳答案

这是正确的行为。

您可以找到更多信息 here .

检查 Chris Banes 的回答。 Chris 在 Google 从事 Android 支持库的工作。

So we've decided that the current behavior is correct. Once you call setSupportActionBar(Toolbar), the Action Bar is then responsible for handling the title, meaning that you need to call getSupportActionBar().setTitle(...) to set a custom title.

然后使用:

setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("My title");

关于android - 方法 setTitle 的工具栏错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30084353/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com