23

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);
Sainath S.R
  • 2,824
  • 8
  • 37
  • 68
yoshatabi
  • 303
  • 1
  • 2
  • 9

7 Answers7

65

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.

Prokash Sarkar
  • 11,334
  • 1
  • 31
  • 48
11

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

Suleiman19
  • 742
  • 1
  • 7
  • 21
  • 5
    Using `android:label=""` is not a good idea. If you have an `` on that Activity to allow users to open your app by clicking a URL (for example), the disambiguation dialog will not have any title! – Albert Vila Calvo Jun 06 '16 at 09:08
10

Try this:

getSupportActionBar().setDisplayShowTitleEnabled(false);
K.Dᴀᴠɪs
  • 9,649
  • 11
  • 33
  • 43
Makvin
  • 3,083
  • 24
  • 26
2

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);
Juanes30
  • 2,093
  • 2
  • 20
  • 35
Sohrab
  • 1,058
  • 4
  • 11
  • 30
0

Add this line to your AppTheme in styles.xml:

<item name="windowActionBar">false</item>
Ali Nem
  • 4,716
  • 1
  • 40
  • 39
0

This line is just important

getSupportActionBar().setDisplayShowTitleEnabled(false);
younes
  • 692
  • 7
  • 8
0

Check your styles.xml

Change your theme to .NoActionBar

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

Hope it helps....