2016-03-25 4 views
0

Ich schaffte es, die Statusleiste durchscheinend zu machen und jetzt habe ich ein Problem mit der Farbe. Aus irgendeinem Grund hat die Statusleiste die gleiche Farbe wie die Symbolleiste, wenn Sie nach oben streichen.Android, Symbolleiste und Statusleiste haben die gleiche Farbe

enter image description here

DetailsActivity.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:background="@color/md_grey_200"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="260dp" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:fitsSystemWindows="true" 
     app:layout_behavior="com.my.package.FlingBehavior"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:titleEnabled="true" 

      <ImageView 
       android:id="@+id/backdrop" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="76dp" 
       android:paddingTop="24dp" 
       app:layout_collapseMode="pin" 
       android:fitsSystemWindows="false" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

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

    <RecyclerView 
     android:id="@+id/details_recyclerview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="10dp" 
     /> 

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

Arten-v21:

<style name="MyFinalTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- ...and here we setting appcompat’s color theme attrs --> 
    <item name="colorPrimary">@color/primary</item> 
    <item name="colorPrimaryDark">@color/primary_dark</item> 
    <item name="colorAccent">@color/primary</item> 
    <item name="android:statusBarColor">@color/primary_dark</item> 
</style> 

Dies ist, was ich die Statusleiste durchscheinend machen verwenden:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    Window w = getWindow(); 
    w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 
} 

Ich habe versucht, die Farbe der Statusleiste in styles-v21 in primary_dark zu ändern, aber es hat nicht funktioniert. Weder hat diese:

w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 
      w.setStatusBarColor(Color.BLUE); 

Colors.xml, wie gewünscht:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="colorPrimary">#00b386</color> 
    <color name="colorPrimaryDark">#008060</color> 
    <color name="colorAccent">#00e6ac</color> 
</resources> 

Was bin ich?

+0

Welche Farbe möchten Sie ändern und in welcher Farbe? bitte angeben. poste deine colors.xml hier. –

+0

Ich möchte die Farbe der Statusleiste in eine dunklere grüne Farbe ändern. Ich habe die colors.xml hinzugefügt – Alec

Antwort

0

Ändern Sie diese Farbe und sehen, was passieren

<item name="colorAccent">@color/primary</item> 

mit

<item name="colorAccent">@color/black</item> 

oder Sie können wie unter

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 
+0

Nichts passiert .... – Alec

+0

Sie stimmen etwas Farbe wie colorAccent = primäre und auch colorPrimary = primäre? –

+0

Ja, aber ich glaube nicht, dass das das Problem ist. – Alec

0

denken Thema wie verwende ich Sie es an die angegebene hinzufügen Aktivität im Stil-21-Paket!

<item name="android:statusBarColor">@android:color/transparent</item> 

und ich sehe Sie setzen Sie dies auf Ihre CoordinatorLayout, wird es bedeuten, dass diese Ansicht wird FULL_SCREEN, also wenn Swipe, wird die statusBar der Symbolleiste des Hintergrund zeigen, weil es transparent ist ..

android:fitsSystemWindows="true" 

Hoffnung zu helfen ..

+0

Sorry, aber es funktioniert nicht. – Alec

0

ändern

<style name="MyFinalTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- ...and here we setting appcompat’s color theme attrs --> 
    <item name="colorPrimary">@color/primary</item> 
    <item name="colorPrimaryDark">@color/primary_dark</item> 
    <item name="colorAccent">@color/primary</item> 
    <item name="android:statusBarColor">@color/primary_dark</item> 
</style> 

zu

<style name="MyFinalTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- ...and here we setting appcompat’s color theme attrs --> 
    <item name="android:colorPrimary">@color/primary</item> 
    <item name="android:colorPrimaryDark">@color/primary_dark</item> 
    <item name="android:colorAccent">@color/primary</item> 
    <item name="android:statusBarColor">@color/primary_dark</item> 
</style> 

Ich hoffe, das hilft.

+0

Es ist noch schlimmer, die Symbolleiste und die Statusleiste sind jetzt weiß. – Alec

+0

haben diese in style-v21 deklarieren? –

+0

Ja, in styles-v21/v22 und v23 – Alec

0

Ich denke, Sie haben eine falsche Vorstellung von dieser Färbung Sache. Ich möchte Ihnen seine Prinzipien erklären.

in colors.xml haben Sie in der Regel 3 Farben von Start in jeder Android-App.sie sind -

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<color name="colorPrimary">#3F51B5</color> 
<color name="colorPrimaryDark">#12AE90</color> 
<color name="colorAccent">#FF4081</color> 
</resources> 
  • colorPrimaryDark

das ist die Farbe, die oberste Farbe in Ihrer Tätigkeit ist, und dies ist die Bar, die das Netzwerk Info, Zeit und alle anderen coolen Sachen enthält. Wenn Sie die Farbe ändern möchten, ändern Sie den entsprechenden Farbcode in der color.xml.

  • colorPrimary

das ist die Farbe der Titelleiste und diese enthält die App-Namen oder die Aktivität vorherigen Namen Sie seine Farbe wollen, dann in der color.xml den jeweiligen Farbcode ändern ändern.

  • colorAccent

das ist die Farbe der Elemente in Ihrer Tätigkeit wie Knöpfe und EditText etc., wenn Sie die Farbe wollen, dann in den color.xml den jeweiligen Farbcode ändern ändern.

Der Farbcode für verschiedene Farben kann here gefunden werden.

Ich denke, meine Antwort löst Ihre Anfrage. Bitte lass es mich wissen, wenn es so ist.

+0

Es funktioniert nicht. Ich habe alle 3 Farben geändert, überprüfe meine colors.xml – Alec

1

Problem gelöst!

1. I entfernt die folgenden Zeilen:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    Window w = getWindow(); 
    w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 
} 

2. I android:fitsSystemWindows="true" zum ImageView hinzugefügt, etwa so:

<ImageView 
    android:id="@+id/backdrop" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:scaleType="centerCrop" 
    app:layout_collapseMode="parallax" /> 

3. die statusBarColor transparenten Changed :

<item name="android:statusBarColor">@color/transparent</item>