Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide app title on support.v7.widget.toolbar

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">
like image 770
masmic Avatar asked May 22 '15 10:05

masmic


People also ask

What is androidx appcompat widget Toolbar?

androidx.appcompat.widget.Toolbar. A standard toolbar for use within application content. A Toolbar is a generalization of action bars for use within application layouts.

What is the layout for Toolbar?

In Android applications, Toolbar is a kind of ViewGroup that can be placed in the XML layouts of an activity. It was introduced by the Google Android team during the release of Android Lollipop(API 21). The Toolbar is basically the advanced successor of the ActionBar.


2 Answers

Use

getSupportActionBar().setDisplayShowTitleEnabled(false);
like image 138
Bojan Kseneman Avatar answered Sep 29 '22 01:09

Bojan Kseneman


Use

getSupportActionBar().setDisplayShowTitleEnabled(false);

Under setContentView() and setSupportActionBar() function.

like image 33
AGM Tazim Avatar answered Sep 29 '22 00:09

AGM Tazim