带有fitsSystemWindows的内部片段

时间:2018-10-06 04:16:50

标签: android android-fragments android-statusbar android-bottom-nav-view

我正在处理透明的状态栏和底部导航栏。我在上一个问题:Gradient status bar with BottomNavigationView

中也取得了相同的成绩
  

但是现在,我有一个片段,其中fitsSystemWindows不是   工作。我有像活动-> Viewpager->片段->这样的布局   Viewpager->子片段。

我已经经历了很多堆栈溢出的尝试,但是仍然没有运气:

  1. Appbar fitsSystemWindows - Inside a ViewPager
  2. Android - ViewPager fitsSystemWindows (fullscreen) not working
  3. Setting a child view to fit system windows
  4. Android fitsSystemWindows not working when replacing fragments
  5. How to apply gradient to status bar in android?

我添加了此样式

<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>

在v21 /样式中:

 <item name="colorPrimaryDark">@android:color/transparent</item>

在布局中,我向每个片段和活动都添加了fitsSystemWindows

活动布局:

<?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>

片段布局之一:

<?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>

0 个答案:

没有答案