Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app always show app name in toolbar

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>
like image 825
juergen d Avatar asked Dec 11 '22 13:12

juergen d


2 Answers

Add label to activity declaration in AndroidManifest.xml file.

    <activity
        ....
        android:label="Name of Your Screen"
        ....
    </activity>
like image 143
JTeam Avatar answered Dec 13 '22 03:12

JTeam


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();
like image 22
abmblob Avatar answered Dec 13 '22 03:12

abmblob