2016-05-25 10 views
0

Wenn ich versuche, die Symbolleiste mit LinearLayout zu verwenden, wird die Statusleiste für Aktivitäten weiß, aber wenn ich das LinearLayout durch CoordinatorLayout ersetze, wird es ordnungsgemäß angezeigt.Android-Statusleiste wird weiß, wenn die Symbolleiste im linearen Layout verwendet wird

<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" 
android:fitsSystemWindows="true" 
android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 
</android.support.design.widget.CoordinatorLayout> 

Dies ist mit Linear Layout

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:fitsSystemWindows="true" 
android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</LinearLayout> 

es auf diese Weise verwendet werden soll, soll, denn wenn ich es vor CoordinatorLayout früher verwendet, es funktioniert?

Unten finden Sie den Screenshot

Antwort

4

Dieses Codezeile in Ihre Werte-v21/styles.xml, dies auf Lollipop zu aktivieren:

<resources> 
<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    <item name="colorPrimary">@color/color_primary</item> 
    <item name="colorPrimaryDark">@color/color_secondary</item> 
    <item name="colorAccent">@color/color_accent</item> 
    <item name="android:statusBarColor">@color/color_primary</item> 
</style> 
</resources> 

Diese Arbeit von Lollipop (API 21)

+0

Ich habe die Stile nicht richtig überprüft. Standardmäßig wurde die Farbe der Statusleiste auf transparent gesetzt. Vielen Dank – Bhushan