Toolbar title not showing with CollapsingToolBarLayout

<android.support.design.widget.AppBarLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <!--    ******************    TOOLBAR    *******************    -->
    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|snap"

        >
        <android.support.v7.widget.Toolbar
            app:layout_scrollFlags="scroll|enterAlways|snap"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar"
            >
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>

      

Hello. My toolbar is not showing, although I installed it in my activity with:

(toolbar.setTitle("TITLE");
        toolbar.setTitleTextColor(0xFFFFFF);

      

I have provided a snip of my .XML file. Since I am a noob, I ask the stackoverflow army for help.

Thanks for helping me.

+3


source to share


1 answer


If you need to login to your activity, you can use the support action bar like this.

on the onCreate

     setSupportActionBar(toolbar);

      

and then when you are about to set the title try this.



     if (getSupportActionBar() != null) {
        if (title!=null) {
            getSupportActionBar().setDisplayShowTitleEnabled(true);
            getSupportActionBar().setTitle(title);
        } else {
            getSupportActionBar().setDisplayShowTitleEnabled(false);
        }
    }

      

If you cannot use the xml option:

    <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:title="TITLE"
    app:popupTheme="@style/AppTheme.PopupOverlay">

      

Hope it helps.

+1


source







All Articles