Is it possible to implement a fading effect for the Toolbar title in Android Studio, where the title slowly fades away as the user scrolls?

31 views Asked by At

Below is my custom toolbar, where i want the title name to slowly fade its color when Scrolled Up and it should also come back to its initial color slowly when Scrolled Down.

is it possible to do it in XML?

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


  <com.google.android.material.appbar.AppBarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/appBarLayout"
    android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar">

        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:title="TITLE"
            app:titleTextColor="@color/white"
            app:layout_scrollFlags="scroll|enterAlways" /> 
   </com.google.android.material.appbar.AppBarLayout>

Below is another XML file where i included above layout

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


  <androidx.coordinatorlayout.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@color/black">

  <include layout="@layout/custom_collapsing_toolbar"/>

  <androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

  </androidx.coordinatorlayout.widget.CoordinatorLayout>
0

There are 0 answers