我正在处理可见的透明状态栏和底部导航栏。我的最后一个问题也达到了同样的效果:Gradient status bar with BottomNavigationView
但是现在,我有一个片段
fitsSystemWindows
不起作用。我有像活动 - > Viewpager - > Fragments - > Viewpager - > child Fragments这样的布局。
我经历了堆栈溢出的许多尝试,但仍然没有运气:
- Appbar 适合SystemWindows - 在 ViewPager 中
- Android - ViewPager 适合SystemWindows(全屏)不工作
- 设置子视图以适应系统窗口
- 替换片段时Android适合SystemWindows不起作用
- 如何将渐变应用于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>