My MainActivity
реализует NavigationView
, поэтому в основном все содержимое экрана находится внутри FrameLayout
.В одном из Fragments
у меня есть ViewPager
, я хочу, чтобы при запуске этого Fragment
, elevation
из Toolbar
удалялся, а в противном случае снова добавлялся.
Мой целевой API - 29, и мне не нужна поддержка более старых версий.
activity_main.xml
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
layout="@layout/toolbar"/>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<include layout="@layout/navigation_drawer"/>
</androidx.drawerlayout.widget.DrawerLayout>
fragment_view_pager.xml
<androidx.viewpager.widget.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabs_vp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs_tl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="?android:attr/colorPrimary">
</com.google.android.material.tabs.TabLayout>
</androidx.viewpager.widget.ViewPager>