android - 删除appcompat-v7中工具栏中的标题
Toolbar的文档说
如果应用使用徽标图片,则应强烈考虑省略标题和副标题。
删除标题的正确方法是什么?
13个解决方案
462 votes
getSupportActionBar().setDisplayShowTitleEnabled(false);
massaimara98 answered 2019-05-26T18:54:18Z
58 votes
隐藏/更改工具栏标题的正确方法是:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
这是因为当您调用setSupportActionBar(toolbar);时,getSupportActionBar()将负责处理Action Bar的所有内容,而不是工具栏对象。
看这里
David_E answered 2019-05-26T18:54:51Z
18 votes
试试这个...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_landing_page);
.....
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_landing_page);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
.....
}
Silambarasan Poonguti answered 2019-05-26T18:55:10Z
13 votes
我对此的回答是因为最受欢迎的答案本身未能解决我的问题。 这样做我已经弄明白了这个问题。
android:label="" />
希望这也会对其他人有所帮助。
Chandra Sekhar answered 2019-05-26T18:55:41Z
9 votes
从Toolbar中删除标题的另一种方法是null,如下所示:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle(null);
MrEngineer13 answered 2019-05-26T18:56:06Z
2 votes
你可以使用下面的任何一个作为两种方式相同的方式:getSupportActionBar().setDisplayShowTitleEnabled(false);和getSupportActionBar().setTitle(null);
在哪里使用:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
要么 :
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
Crime_Master_GoGo answered 2019-05-26T18:56:34Z
2 votes
Toolbar actionBar = (Toolbar)findViewById(R.id.toolbar);
actionBar.addView(view);
setSupportActionBar(actionBar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
请注意这一行getSupportActionBar().setDisplayShowTitleEnabled(false);
suulisin answered 2019-05-26T18:56:59Z
2 votes
如果您使用的是工具栏,请尝试以下代码:
toolbar.setTitle("");
varotariya vajsi answered 2019-05-26T18:57:24Z
1 votes
我不知道这是否正确,但我改变了我的风格。
@color/colorPrimary
@color/colorPrimaryDark
@color/colorAccent
false
true
Goudam m answered 2019-05-26T18:57:49Z
1 votes
这个
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
//toolbar.setNavigationIcon(R.drawable.ic_toolbar);
toolbar.setTitle("");
toolbar.setSubtitle("");
//toolbar.setLogo(R.drawable.ic_toolbar);
younes answered 2019-05-26T18:58:14Z
0 votes
隐藏ToolBar标题/标签的正确方法以下代码:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
Hai Rom answered 2019-05-26T18:58:40Z
0 votes
没有人提到:
@Override
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
}
Andoctorey answered 2019-05-26T18:59:05Z
0 votes
toolbar.setTitle(null); //删除标题
user2167877 answered 2019-05-26T18:59:30Z