0

我有以下布局:第一项下没有状态栏去

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.skillberg.weather.ui.activity.MainActivity"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/weather_rv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:fitsSystemWindows="true" /> 


</android.support.design.widget.CoordinatorLayout> 

和风格:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 

     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
     <item name="windowActionBarOverlay">true</item> 
     <item name="android:statusBarColor">@android:color/transparent</item> 
    </style> 

我想要的状态栏下显示在RecyclerView的第一个项目(如工具栏),但它没有显示有:

enter image description here

然而,RecyclerView本身吸引下,状态栏,但似乎有一些顶级的填充其高度=状态栏的高度:

enter image description here

如何解决呢?这android:fitsSystemWindows="true"false

+1

从RecyclerView删除android:fitsSystemWindows =“true” –

+0

@VinayakB如果我删除它,它位于状态栏下方:https://i.imgur.com/RFySVcx.jpg – arts777

+0

为什么不添加 true在你的风格 –

回答

2

扩展您AppThemewindowTranslucentStatus例如

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:windowTranslucentStatus">true</item> 
     // other stuff 
</style> 

这将允许StatusBar是透明的。您不需要使用android:fitsSystemWindows

+0

谢谢,工作! – arts777

+0

还有一个问题:有没有一种方法可以去除灰色:https://i.imgur.com/UuBi251。 png?我试过谷歌,但没有任何帮助 – arts777

+0

灰色色调? – Ankita

0

在你CoordinatorLayout改变。 只需将它添加到您的RecyclerView如下:

<android.support.v7.widget.RecyclerView 
    android:id="@+id/weather_rv" 
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/white" 
    android:fitsSystemWindows="true" /> 

0

你错过了,在对与CoordinatorLayout作品的行为

+0

没有什么变化:( – arts777