android – How to remove app title from toolbar?-ThrowExceptions

Exception or error:

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

Here is how my MainActivity looks:

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

Full code:

 @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);
How to solve:

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.

###

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

###

Try this:

getSupportActionBar().setDisplayShowTitleEnabled(false);

###

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

###

Add this line to your AppTheme in styles.xml:

<item name="windowActionBar">false</item>

###

This line is just important

getSupportActionBar().setDisplayShowTitleEnabled(false);

###

Check your styles.xml

Change your theme to .NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Hope it helps….

Leave a Reply

Your email address will not be published. Required fields are marked *