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
  • 3,074
  • 9
  • 41
  • 72
yoshatabi
  • 303
  • 1
  • 2
  • 9

8 Answers8

69

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,723
  • 1
  • 37
  • 50
12

Try this:

getSupportActionBar().setDisplayShowTitleEnabled(false);
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
Makvin
  • 3,475
  • 27
  • 26
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
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,398
  • 2
  • 24
  • 38
Sohrab
  • 1,348
  • 4
  • 13
  • 33
1

Check your styles.xml

Change your theme to .NoActionBar

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

Hope it helps....

0

Add this line to your AppTheme in styles.xml:

<item name="windowActionBar">false</item>
Ali Nem
  • 5,252
  • 1
  • 42
  • 41
0

This line is just important

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

Just Write this{ } in manifest file.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • This does not match https://stackoverflow.com/a/31096547/7733418 so what are you talking about? Do you even attempt to answer the question? Or is this only "Thanks"? Even if somewhat mistaken for what. If you cannot [edit] this into an answer according to [answer] please delete it. – Yunnosch Jan 02 '23 at 08:03
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 02 '23 at 10:49