Remove title in Toolbar in appcompat-v7

前端 未结 18 1412
孤街浪徒
孤街浪徒 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:34

    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);
    
    0 讨论(0)
  • 2020-12-07 10:34

    I dont know whether this is the correct way or not but I have changed my style like this.

    <style name="NoActionBarStyle" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>
    
    0 讨论(0)
  • 2020-12-07 10:35

    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);
    
        .....
    
     }
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-07 10:36

    toolbar.setTitle(null);// remove the title

    0 讨论(0)
  • 2020-12-07 10:36

    Just adding an empty string in the label of <application> (not <activity>) in AndroidMenifest.xmllike that -

    <application
                android:label=""
                android:theme="@style/AppTheme">
                <activity
                 .
                 .
                 .
                 .
                </activity>
        </application>
    
    0 讨论(0)
提交回复
热议问题