问题
I am working on the transparent status bar and bottom navigation bar visible. I have achieved the same with my last question: Gradient status bar with BottomNavigationView
But now, I have a fragments in which
fitsSystemWindows
is not working. I have layout like Activity -> Viewpager -> Fragments -> Viewpager -> child Fragments.
I have gone through many attempts from stack overflow but still no luck :
- Appbar fitsSystemWindows - Inside a ViewPager
- Android - ViewPager fitsSystemWindows (fullscreen) not working
- Setting a child view to fit system windows
- Android fitsSystemWindows not working when replacing fragments
- How to apply gradient to status bar in android?
I have added this styles :
<item name="android:windowContentOverlay">@null</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:navigationBarColor">#000</item>
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorPrimaryDark">@android:color/transparent</item>
In v21/style :
<item name="colorPrimaryDark">@android:color/transparent</item>
In layout, I have added fitsSystemWindows
to each fragment as well as activity.
Activity layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.mobile.lendlease.views.WrapContentViewPagerBottomTab
android:id="@+id/viewPagerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/viewDivider"
android:fitsSystemWindows="true" />
<View
android:id="@+id/viewDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_above="@+id/bottomNavigation"
android:background="@color/default_border" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="@dimen/margin_12"
android:paddingEnd="@dimen/margin_12"
android:paddingStart="@dimen/margin_10"
android:paddingTop="@dimen/margin_10"
app:itemBackground="@color/white"
app:menu="@menu/navigation" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>
One of fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorScreenBackground"
android:focusable="true"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:layout_marginBottom="@dimen/margin_20"
android:background="@drawable/toolbar"
android:gravity="bottom"
android:fitsSystemWindows="true"
app:layout_scrollFlags="enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="@dimen/margin_18">
<ImageView
android:id="@+id/ivHome"
android:layout_width="159dp"
android:layout_height="29dp"
android:scaleType="centerInside"
android:src="@drawable/logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">
<ImageView
android:id="@+id/ivSearch"
android:layout_width="@dimen/margin_47"
android:layout_height="32dp"
android:contentDescription="@string/app_name"
android:scaleType="fitXY"
android:src="@drawable/ic_search" />
<TextView
android:id="@+id/ivMall"
style="@style/notoSansSemiBoldStyle"
android:layout_width="58dp"
android:layout_height="32dp"
android:layout_marginEnd="@dimen/margin_18"
android:layout_marginStart="@dimen/margin_10"
android:background="@drawable/search_bg_shape"
android:gravity="center"
android:text="@string/mall_all"
android:textAllCaps="false"
android:textColor="@color/gradient_card_color1"
android:textSize="@dimen/font_12"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:minHeight="?attr/actionBarSize"
app:tabBackground="@drawable/tab_indicator_line_selected"
app:tabGravity="center"
app:tabIndicatorColor="@android:color/transparent"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/colorBlackLight"
app:tabTextAppearance="@style/themeTabText"
app:tabTextColor="@color/colorBlackLight" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPagerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>
来源:https://stackoverflow.com/questions/52675652/inner-fragment-with-fitssystemwindows