Leonardo Leonardo - 2 months ago 11
Android Question

Collapsing Toolbar layout setTitle doesn't work

I'm trying to do a nestedScrollview with collapsing toolbar but when I call in my activity collapsingToolbar.setTitle("my title") it doesn't work.
Here is my xml:

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/coordinatorLayout"
>

<android.support.design.widget.AppBarLayout
android:layout_height="192dp"
android:layout_width="match_parent">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/coll_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:id="@+id/view_toolbar">

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

<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/abc_ic_menu_cut_mtrl_alpha" android:id="@+id/image_btn"
android:background="#00ffffff" android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:paddingRight="15dp"/>

</RelativeLayout>

</android.support.v7.widget.Toolbar>

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView

android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/textee"
android:text="svsdvsdvbshvdfcbsdvbsvbshdbvsdvsdhvbsdhvbsdhvbsdhvbsdhvbsdhbvsdhvbsdhvbsdhbvsdhvbsdhbvsdhbvsdhbvsdhdbvshdbvshdbvshbvsdhbvsdhbvsdhvbsdhvbsdhvbsdhvbsdhvb"
android:textColor="#000000" android:textSize="34dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</RelativeLayout>

</android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>


and here I call setTitle

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

CollapsingToolbarLayout collToolbar = (CollapsingToolbarLayout) findViewById(R.id.coll_toolbar);

Toolbar toolbar = (Toolbar) findViewById(R.id.view_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

collToolbar.setTitle("Caccaaa!!");




And how do I change the color of the arrow and the scissors?
I tried using
<item name="titleTextColor">#FFFFFF</item>
in my theme but it doesn't work
Thanks!

Answer

I suspect what is happenning, is that your is showing up when your toolbar is collapsing...

Remove this code for starters (then maybe refactor differently for your needs):

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

            <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content"
                         android:src="@drawable/abc_ic_menu_cut_mtrl_alpha" android:id="@+id/image_btn"
                         android:background="#00ffffff" android:layout_alignParentTop="true"
                         android:layout_alignParentEnd="true"
                         android:paddingRight="15dp"/>

        </RelativeLayout>
Comments