0

J'ai la disposition suivante:Premier élément RecyclerView ne va pas sous la barre d'état

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

et le style:

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

Je veux que le premier élément de RecyclerView à afficher sous la barre d'état (comme la barre d'outils), mais il est pas là affiché:

enter image description here

Cependant, RecyclerView se dessine sous la barre d'état, mais il semble qu'il y ait une certaine rembourrage supérieure dont la hauteur = hauteur de la barre d'état:

enter image description here

Comment résoudre ce problème?

+1

supprimer android: fitsSystemWindows = « true » de RecyclerView –

+0

@VinayakB si je le supprimer, il positionne en dessous de la barre d'état: https://i.imgur.com/RFySVcx.jpg – arts777

+0

pourquoi ne pas vous ajoutez true dans votre style –

Répondre

2

Élargissez vos AppTheme avec windowTranslucentStatus par exemple

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

Ceci permettra au StatusBar d'être transparent. Vous n'avez pas besoin d'utiliser android:fitsSystemWindows.

+0

Merci, cela a fonctionné! – arts777

+0

Encore une question: est-il un moyen de supprimer la teinte grise: https://i.imgur.com/UuBi251. png? J'ai essayé de google, mais rien n'a aidé – arts777

+0

quelle teinte grise? – Ankita

0

En vous CoordinatorLayout changer cette android:fitsSystemWindows="true"-false

0

vous manque le comportement qui fonctionne en paire avec le CoordinatorLayout. Ajoutez simplement à votre RecyclerView comme suit:

<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

Rien n'a changé :( – arts777