Remove title in Toolbar in appcompat-v7

前端 未结 18 1598
孤街浪徒
孤街浪徒 2020-12-07 09:52

The documentation of Toolbar says

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

18条回答
  •  借酒劲吻你
    2020-12-07 10:36

    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.

    See here

提交回复
热议问题