Home » Android » android – Hide app title on support.v7.widget.toolbar

android – Hide app title on support.v7.widget.toolbar

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m starting to develop a new app and I’m triying to give it a material design look. For this, I’m using the v7 support compatibility.

In some activities of the app, I need the toolbar not to show the app title that, I don’t know how, but it is showing by default. In those activities, I have a textview at the right side of the toolbar that acts like a button, and where I have implemented traex’s RippleEffect.

So, basically my question is, how can I hide the app’s title from the toolbar? Because even if I do:

toolbar.setTitle("");

or

toolbar.setTitle(null);

it continues appearing.

This is my code:

Custom toolbar xml [toolbar_intro.xml]:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    xmlns:ripple="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/tools"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    <com.andexert.library.RippleView
        android:id="@+id/more"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        android:layout_marginRight="40dp"
        ripple:rv_centered="false"
        app:rv_rippleDuration="1">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar_text"
            android:textColor="@color/White"
            android:textStyle="bold"
            android:textSize="25sp"
            android:text="Next"/>
    </com.andexert.library.RippleView>
</android.support.v7.widget.Toolbar>

This is how I include the toolbar in the layout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar_intro" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageView
            ...

    </RelativeLayout>
</LinearLayout>

And this is the activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.intro_wellcome);

    toolbar= (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        toolbar.setTitle("");
    }

    TextView toolbar_text = (TextView) toolbar.findViewById(R.id.toolbar_text);
    toolbar_text.setText(R.string.next);

    ...

}

Also, this is the style that I have implemented:

<style name="MaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
How to&Answers:

Use

getSupportActionBar().setDisplayShowTitleEnabled(false);

Answer:

Use

getSupportActionBar().setDisplayShowTitleEnabled(false);

Under setContentView() and setSupportActionBar() function.

Answer:

getSupportActionBar.setTitle("");