Android 透明的AppBarLayout工具栏并将内容放置在其后面
到目前为止,我已经成功地实现了AppBarLayout和带有滚动标志和AppBar滚动行为的工具栏,一切都很好。我的最终目标是实现如下内容: 正如您所看到的,AppBar是透明的,内容就在它后面。其他一切都很完美 根据我在放置app:layout_behavior=“@string/appbar_scrolling_view_behavior”(在我的例子中,我使用app:layout_behavior=“com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior”)时的观察,标记Coordinator布局不允许我重叠视图(在这种情况下,appbar应该重叠我的内容) 这是我的XML:Android 透明的AppBarLayout工具栏并将内容放置在其后面,android,android-layout,android-toolbar,android-appbarlayout,Android,Android Layout,Android Toolbar,Android Appbarlayout,到目前为止,我已经成功地实现了AppBarLayout和带有滚动标志和AppBar滚动行为的工具栏,一切都很好。我的最终目标是实现如下内容: 正如您所看到的,AppBar是透明的,内容就在它后面。其他一切都很完美 根据我在放置app:layout_behavior=“@string/appbar_scrolling_view_behavior”(在我的例子中,我使用app:layout_behavior=“com.google.android.material.appbar.AppBarLay
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawerLayout"
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:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<fragment
android:id="@+id/fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="@navigation/root_nav_graph"
app:defaultNavHost="true"
/>
</FrameLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
>
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap"
/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
该片段以NestedScrollView作为根保存布局。删除该属性
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
从框架布局。另外,将属性android:background=“@android:color/transparent”
设置到工具栏。删除该属性
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
从框架布局。另外,将属性
android:background=“@android:color/transparent”
设置到您的工具栏上。嘿,您找到解决方案了吗?没有,我没有。我放弃了这个,因为我不能为一个项目在这个问题上花费更多的时间。我希望有人能找到解决办法。此外,最有可能的自定义布局行为类是需要的。我也在寻找类似的东西。有什么想法吗?我会在我的下一个项目中做类似的事情,我会告诉你事情的进展:)嘿,你找到解决办法了吗?没有,我没有。我放弃了这个,因为我不能为一个项目在这个问题上花费更多的时间。我希望有人能找到解决办法。此外,最有可能的自定义布局行为类是需要的。我也在寻找类似的东西。有什么想法吗?我会在我的下一个项目中做类似的事情,我会告诉你事情的进展:)