android v7隐藏标题,android - 删除appcompat-v7中工具栏中的标题

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值