2017-01-06 3 views
1

У меня есть приложение с DrawerLayout который содержит NavigationView:Android DrawerLayout (с NavigationView) за строкой состояния

activity_layout.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/drawer_layout" 
    android:fitsSystemWindows="true"> 

    <android.support.constraint.ConstraintLayout 
     android:id="@+id/activity_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.exmaple.appname.activityname"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/actionbar_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:elevation="4dp" 
      android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
      app:popupTheme="@style/Theme.AppCompat"/> 

     […] 

    </android.support.constraint.ConstraintLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:menu="@menu/nav_drawer" 
     android:fitsSystemWindows="true"/> 

</android.support.v4.widget.DrawerLayout> 

Я добавил следующие стили, а также:

styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar"> 
    […] 

    <item name="windowActionBar">false</item> 
    <item name="android:windowNoTitle">true</item> 
</style> 

значения-21/styles.xml:

<style name="AppTheme.NoActionBar" parent="AppTheme"> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
</style> 

Все этот код основан на Google I/O Schedule App, однако DrawerLayout до сих пор не делает за строкой состояния. Любые идеи относительно того, почему эта комбинация решений не работает и какие решения могут? Я обнаружил, что рисование за панель состояния никогда не является решением для каждого размера, но после попытки каждой комбинации решений в Stack Overflow, о которой я могу думать, я все равно не могу ее получить.

Текущий ящик изображения: enter image description here

ответ

1

Просто добавьте <item name="android:windowTranslucentStatus">true</item> в values-21/styles.xml и удалить этот <item name="android:statusBarColor">@android:color/transparent</item>

добавить android:fitsSystemWindows="true" к вашему NavigationView в XML

Работа пример!

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:windowTranslucentStatus">true</item> 
</style> 

Результат enter image description here

Edited (основной макет)

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" <--This is mandatory 
    tools:context=".ui.activities.MainActivity"> 

    <FrameLayout 
     android:id="@+id/frame_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white" /> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/colorPrimary" 
     android:fitsSystemWindows="true" /><--This is mandatory 

</android.support.v4.widget.DrawerLayout> 

Текущий результат enter image description here

Обновление: Я Lookup свой стиль-V21 и найти ниже

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="AppTheme.NoActionBar" parent="AppTheme"> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="android:windowTranslucentStatus">true</item> 
    </style> 
</resources> 

Пожалуйста, замените его с этим

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:windowTranslucentStatus">true</item> 
</style> 
+0

Nope. Я отключил 'statusBarColor' для' windowTranslucentStatus' (в 'v21') без везения. Затем я добавил 'fistsSystemWindows' в' NavigationView' (хотя я не использую заголовок и не хочу, чтобы он находился за строкой состояния), и все равно ничего. Цвет фона «NavigationView» по-прежнему только отображается в строке состояния. В ближайшее время я буду работать над предоставлением полного кода. – RedBassett

+0

(Исправление выше: я хочу, чтобы 'NavigationView' был' fitsSystemWindow', так как это тот фон, который я хочу расширить за строкой состояния) – RedBassett

+0

Обновлено с изображением в исходном вопросе. Я хочу, что вы показали, но без изображения заголовка. Цвет фона ящика должен простираться за панель состояния. – RedBassett

Смежные вопросы