Android 在 appcompat-v7 中删除工具栏中的标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26648227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 12:00:50  来源:igfitidea点击:

Remove title in Toolbar in appcompat-v7

androidandroid-actionbarandroid-appcompatandroid-toolbar

提问by Shubhadeep Chaudhuri

The documentationof Toolbarsays

文件Toolbar

If an app uses a logo image it should strongly consider omitting a title and subtitle.

如果应用程序使用徽标图像,则应强烈考虑省略标题和副标题。

What is the proper way to remove the title?

删除标题的正确方法是什么?

回答by massaimara98

getSupportActionBar().setDisplayShowTitleEnabled(false);

回答by David_E

The correct way to hide/change the Toolbar Title is this:

隐藏/更改工具栏标题的正确方法是:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);

This because when you call setSupportActionBar(toolbar);, then the getSupportActionBar()will be responsible of handling everything to the Action Bar, not the toolbar object.

这是因为当您调用 时setSupportActionBar(toolbar);getSupportActionBar()将负责处理操作栏的所有内容,而不是工具栏对象。

See here

这里

回答by Silambarasan Poonguti

Try this...

尝试这个...

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

    .....

 }

回答by Chandra Sekhar

The reason for my answer on this is because the most upvoted answer itself failed to solve my problem. I have figured out this problem by doing this.

我回答这个问题的原因是因为最高投票的答案本身未能解决我的问题。我已经通过这样做解决了这个问题。

<activity android:name="NAME OF YOUR ACTIVITY"
    android:label="" />

Hope this will help others too.

希望这也能帮助其他人。

回答by MrEngineer13

Another way to remove the title from your Toolbaris to nullit out like so:

另一种从你的标题中删除标题的方法Toolbarnull这样的:

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
toolbar.setTitle(null);

回答by younes

this

这个

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

回答by varotariya vajsi

If you are using Toolbar try below code:

如果您使用的是工具栏,请尝试以下代码:

toolbar.setTitle("");

回答by Dyno Cris

Just add this attribute to your toolbar

只需将此属性添加到您的工具栏

app:title=" "

回答by Crime_Master_GoGo

You can use any one of bellow as both works same way:getSupportActionBar().setDisplayShowTitleEnabled(false);andgetSupportActionBar().setTitle(null);

您可以使用以下任何一种,因为两者的工作方式相同:getSupportActionBar().setDisplayShowTitleEnabled(false);getSupportActionBar().setTitle(null);

Where to use:

使用地点:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

Or :

或者 :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setTitle(null);

回答by suulisin

 Toolbar actionBar = (Toolbar)findViewById(R.id.toolbar);
    actionBar.addView(view);
    setSupportActionBar(actionBar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

take note of this line getSupportActionBar().setDisplayShowTitleEnabled(false);

注意这一行 getSupportActionBar().setDisplayShowTitleEnabled(false);