如何从工具栏删除应用程序标题? [英] How to remove app title from toolbar?

查看:74
本文介绍了如何从工具栏删除应用程序标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何删除标题.我在MainActivity中使用了以下代码,但是在添加该行之后,我的应用程序崩溃了.

I can't figure out how to remove my title. I've used the code below in my MainActivity but after I added that line, my app crashes.

getSupportActionBar().setDisplayShowTitleEnabled(false);

这是我的MainActivity外观:

Here is how my MainActivity looks:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

完整代码:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        setContentView(R.layout.activity_main);
        setTheme(R.style.CustomTheme);

推荐答案

尝试一下,

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

如果仍然无法使用,请使用 setNavigationIcon()& setLogo(),并且应该替换标题.如果您遇到任何崩溃,请发布崩溃报告.

If still doesn't works just use setNavigationIcon() & setLogo() and that should replace the title. If you are facing any crashes please post the crash report.

这篇关于如何从工具栏删除应用程序标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆