方法 setTitle 的工具栏错误
Toolbar bug with method setTitle
我在我的工具栏中使用了这两种方法:
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");
我在我的工具栏中使用了这两种方法:
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 callgetSupportActionBar().setTitle(...)
to set a custom title.
然后使用:
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("My title");