是否可以在 Android Studio 中为工具栏标题实现淡入淡出效果,其中标题会随着用户滚动而慢慢淡出?

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?

提问人:Sourav Karjole 提问时间:9/29/2023 最后编辑:Sourav Karjole 更新时间:9/29/2023 访问量:13

问:

下面是我的自定义工具栏,我希望标题名称在向上滚动时慢慢褪色,在向下滚动时也应该慢慢恢复到初始颜色。

是否可以在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>

下面是我包含上述布局的另一个XML文件

  <?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>
android-studio android-layout android-toolbar android-xml

评论


答: 暂无答案