2016-03-29 8 views
1

Wenn ich das durchscheinend Navigationsleiste mitDurchlässiger Navigationsleiste ist eine Farbe

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 

Dann wird die Werkzeugleiste befindet sich hinter der Statusbar (die Statusbar soll gefärbt werden, aber die navbar soll durchlässig sein) ermöglichen. Wenn ich jedoch für diese Aktivität zum Layout-XML gehe und android:fitsSystemWindows="true" einfüge, ist die Symbolleiste korrekt angelegt, aber die Navigationsleiste ist dann einfarbig. Hier

ist das Layout:

<?xml version="1.0" encoding="utf-8"?> 
<me.ccrama.redditslide.Views.SidebarLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:background="?attr/activity_background"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <View 
      android:id="@+id/anchor" 
      android:layout_width="1dp" 
      android:layout_marginTop="4dp" 
      android:layout_marginRight="3dp" 

      android:layout_gravity="top|right" 
      android:layout_height="1dp" /> 

     <me.ccrama.redditslide.Views.ToggleSwipeViewPager 
      android:id="@+id/content_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

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

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:minHeight="56dp" 
       android:layout_height="?android:attr/actionBarSize" 
       android:theme="@style/ActionBarCompat" 
       android:title="@string/app_name" /> 

      <ViewStub 
       android:id="@+id/stub_tabs" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:inflatedId="@+id/sliding_tabs" 
       android:layout="@layout/activity_overview_tabs" /> 

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


    </FrameLayout> 

    <ListView 
     android:id="@+id/drawerlistview" 
     android:layout_width="300dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="?attr/card_background" 
     android:orientation="vertical" /> 

    <include 
     layout="@layout/subinfo" 
     android:layout_width="300dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="end" /> 

</me.ccrama.redditslide.Views.SidebarLayout> 

Das gleiche Verhalten (farbige navbar) passiert, wenn ich die android:fitsSystemWindows="true" innerhalb der FrameLayout stattdessen setzen.

Das erste Bild unten ist, wenn das Symbolleisten-Layout durcheinander ist, und das zweite Telefon ist, wenn die Navigationsleiste nicht durchscheinend ist.

enter image description here

enter image description here

+0

getWindow() setStatusBarColor (Color.TRANSPARENT) ; –

+0

aber was ist, wenn ich die Statusleiste gefärbt habe? Ich habe es bereits auf rot gesetzt. – Nxt3

+0

Was ist Ihre Bedeutung? –

Antwort

1

Verwendung Thema unten als Ihre Aktivität Thema:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

Und verwenden getNavigationBarColor (Color.TRANSPARENT);

Window

  /** 
    * Flag indicating that this Window is responsible for drawing the background for the 
    * system bars. If set, the system bars are drawn with a transparent background and the 
    * corresponding areas in this window are filled with the colors specified in 
    * {@link Window#getStatusBarColor()} and {@link Window#getNavigationBarColor()}. 
    */ 
    public static final int FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000; 


    /** 
    * Window flag: request a translucent status bar with minimal system-provided 
    * background protection. 
    * 
    * <p>This flag can be controlled in your theme through the 
    * {@link android.R.attr#windowTranslucentStatus} attribute; this attribute 
    * is automatically set for you in the standard translucent decor themes 
    * such as 
    * {@link android.R.style#Theme_Holo_NoActionBar_TranslucentDecor}, 
    * {@link android.R.style#Theme_Holo_Light_NoActionBar_TranslucentDecor}, 
    * {@link android.R.style#Theme_DeviceDefault_NoActionBar_TranslucentDecor}, and 
    * {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor}.</p> 
    * 
    * <p>When this flag is enabled for a window, it automatically sets 
    * the system UI visibility flags {@link View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and 
    * {@link View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.</p> 
    */ 
    public static final int FLAG_TRANSLUCENT_STATUS = 0x04000000; 

Fenster

/** 
* Sets the color of the status bar to {@code color}. 
* 
* For this to take effect, 
* the window must be drawing the system bar backgrounds with 
* {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS} and 
* {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_STATUS} must not be set. 
* 
* If {@code color} is not opaque, consider setting 
* {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and 
* {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. 
* <p> 
* The transitionName for the view background will be "android:status:background". 
* </p> 
*/ 
public abstract void setStatusBarColor(@ColorInt int color); 
+0

Es tut mir leid - was? Du hast gesagt "Entferne unten"? Außerdem möchte ich nicht, dass die Statusleiste transparent ist - NUR die Navigationsleiste. – Nxt3

+0

Ich meine, dass Sie den oben aufgeführten Code entfernen sollten. Bitte geben Sie Ihren Code des Themas an. –

+0

Ich habe keinen Code irgendwo. Ich habe meinen ganzen relevanten Code gepostet, für den ich die Navbar transluzent einstellen muss. – Nxt3

0

Von doc

Wenn Sie ein eigenes Thema erstellen, Set eines dieser Themen als Mutter Thema oder sind die windowTranslucentStatus styleTranslucentStatus styleTranslucentStatus pr Operetten in Ihrem Thema.

So können Sie unter Thema verwenden, aber für Api 19+:

Werte

<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo"> 
</style> 

<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">#673AB7</item> 
    <item name="colorPrimaryDark">#512DA8</item> 
    <item name="colorAccent">#FF4081</item> 
    <item name="android:windowTranslucentNavigation">true</item> 
</style> 

Werte-21.

<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo"> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="android:statusBarColor">@android:color/transparent</item> 
    </style> 
+0

Müsste ich noch den Java-Teil machen, um Transluzenz zu setzen? Ich hatte bereits versucht, was Sie vorgeschlagen haben und es hat nicht funktioniert. – Nxt3

+0

Ich habe es auf Lolipop ohne Flagge versucht und es hat funktioniert, ich weiß nicht, was Ihr Problem ist, versuchen Sie es. –

+0

Ich habe alle Stile hinzugefügt –

Verwandte Themen