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