4

I want to show a specific text in my app toolbar but it also always shows the name of the app too. How can I get rid of the app name and only the text of the TextView?

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay"
    android:fitsSystemWindows="true" >

    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        android:fitsSystemWindows="true" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="The title I want to show"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true" />

    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
juergen d
  • 201,996
  • 37
  • 293
  • 362

5 Answers5

6

Add label to activity declaration in AndroidManifest.xml file.

    <activity
        ....
        android:label="Name of Your Screen"
        ....
    </activity>
JTeam
  • 1,455
  • 1
  • 11
  • 16
4

For static activity name, set android:label="Activity Name" attribute for each activity in AndroidManifest.xml

...
<activity
    ...
    android:label="Activity Name">
    ...
</activity>
...

For dynamic activity name, you can use the following:

getActionBar().setTitle("Activity Name");

To provide compatibility across all the android versions, use:

getSupportActionBar().setTitle("Activity Name"); 

But if you want to completely get rid of the title bar, you can extend Activity instead of AppCompatActivity or you can hide the action bar:

ActionBar actionBar = getSupportActionBar();
actionBar.hide();
abmblob
  • 361
  • 2
  • 14
4

you just write this line in your activity getSupportActionBar().setDisplayShowTitleEnabled(false);

and it will set the visibility of the app name to invisible

0

Use

<activity 
    android:label="blah-blah" /> 

to set it in the manifest file.
Or in the code toolbar.setTitle("blah-blah");
If you set your Toolbar like ActionBar then you can call actionBar.setTitle("blah-blah");.

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
0

From the modification of the accepted answer, this actually resolved my issue.

All you need to do is to leave the "label name" text as blank in your manifest as example below

...
<activity
    ...
    android:label="  ">
    ...
</activity>
...

this will actually enable only your textview text in your toolbar widget to show, it works very fine for me