12

Ich versuche, CoordinatorLayout und seine Funktionen zu lernen. Ich habe es in Verbindung mit AppBarLayout verwendet. Mein xml ist wie folgt:Symbolleiste scrollen unter der Statusleiste

Das Problem, mit dem ich konfrontiert bin, ist, dass die Symbolleiste beim Scrollen unter die Statusleiste geht. Ich möchte, dass die Symbolleiste blättert, wenn ich in der Recycler-Ansicht blättere, aber ich möchte nicht, dass sie in der Statusleiste angezeigt wird. Wie verhindere ich dies?

Wenn ich versuche, das CoordinatorLayout in ein anderes Layout zu kapseln, zB: LinearLayout, wird die im Theme definierte primaryDark-Farbe nicht in der Statusleiste angezeigt. Es zeigt die primaryDark-Farbe, wenn ich es wie oben xml verwende. Gibt es einen besseren Weg, dies zu tun?

Antwort

11

Ich reparierte das, indem ich in den Stil ging, der die Statusbarfarbe steuert und änderte es zu der Farbe, die ich anstelle von transparentem wollte. Jetzt scheint die Statusleiste über der Symbolleiste zu sein.

<resources>> 
<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
</style> 

`

<resources>> 
<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
    <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    <item name="android:statusBarColor">@color/colorPrimaryDark</item> 
</style> 

7

hatte ich das ähnliche Problem. Meine war gelöst.

Der AppArBarLayout wurde android:fitsSystemWindows="true" hinzugefügt. Hinzugefügt app:layout_scrollFlags="scroll|enterAlways|snap" für Toolbar Unten ist das Layout, das ich hatte.

<android.support.design.widget.CoordinatorLayout 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" 
tools:context=".HomeActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.AppBarOverlay"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways|snap" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/id_tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

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

<android.support.v4.view.ViewPager 
    android:id="@+id/id_viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_dialog_email"/> 
+0

Ich habe fälschlicherweise 'android: fitsSystemWindows =" true "' zu CoordinatorLayout hinzugefügt. Das Problem ist jetzt gelöst, indem Sie 'android: fitsSystemWindows =" true "' aus CoordinatorLayout entfernen, das die Stammansicht war, und stattdessen zu AppbarLayout hinzufügen. –

0

können Sie Stammansicht Tag CoordinatorLayout und fitsystemwindows = true wieder hinzufügen.