How to remove app title from toolbar?

前端 未结 7 1804
予麋鹿
予麋鹿 2020-12-29 05:28

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.

getSuppor         


        
相关标签:
7条回答
  • 2020-12-29 05:36

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

    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.

    0 讨论(0)
  • 2020-12-29 05:36

    This is my gradle:

    android {
        compileSdkVersion 26
        buildToolsVersion '27.0.3'
        defaultConfig {
            applicationId "com.example.zumoappname"
            minSdkVersion 19
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
    

    and this is my activity:

     public class MainActivity extends AppCompatActivity {
     .....
    

    The following code works very nice for me:

    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    myToolbar.setTitle("");
    setSupportActionBar(myToolbar);
    
    0 讨论(0)
  • 2020-12-29 05:46

    This line is just important

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    
    0 讨论(0)
  • 2020-12-29 05:49

    You can use toolbar.setTitle(""); Or you can simply set the android:label="" for your Activity in the AndroidManifest.xml

    0 讨论(0)
  • 2020-12-29 05:53

    Add this line to your AppTheme in styles.xml:

    <item name="windowActionBar">false</item>
    
    0 讨论(0)
  • 2020-12-29 05:55

    Try this:

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    
    0 讨论(0)
提交回复
热议问题