2016-01-24 18 views
11

Aus irgendeinem Grund ist die Statusleiste jetzt weiß. Oder eher ein gebrochenes Weiß, mit einem anderen Farbton von Weiß für die Ikonen, die gegen den hellen Hintergrund schwach sichtbar sind. Was falsch ist, weil mein Appbarlayout einen blauen Farbton als Farbe verwendet. Bis jetzt hat das gut funktioniert, ich weiß nicht, was ich getan habe, um das zu verursachen. Ich habe versucht, die statusBarColor manuell auf colorPrimaryDark (# 0277bd) zu setzen, aber es funktioniert nicht.Android: Statusleiste ist Weiß

Ich weiß einfach nicht, warum das in erster Linie passiert. Ich habe die layout.xml meiner Aktivität eingefügt, vielleicht kann mir jemand sagen, was ich hier falsch mache.

Ein paar Anmerkungen:

Die verwendeten Themen wurden nicht von ihren Standardeinstellungen geändert, die die Primärfarbeinstellungen zu verwenden sind. Ich habe diese auf den richtigen Blauton geändert, den ich wollte, aber als ich die Änderung durchführte, funktionierte alles.

Mein layout.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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:statusBarColor="@color/colorPrimaryDark" 
    tools:context=".activities.ContactsActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/contactsActivityAppbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:statusBarColor="@color/colorPrimaryDark" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/contactsActivityToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 
     <!-- app:layout_scrollFlags="scroll|enterAlways" --> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/contactsActivityTabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabIndicatorColor="@android:color/white" 
      android:scrollbarStyle="insideOverlay" 
      android:paddingBottom="1dp" 
      android:background="@color/colorPrimary"/> 

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

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

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

Colors.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="colorPrimary">#0288d1</color> 
    <color name="colorPrimaryDark">#0277bd</color> 
    <color name="colorAccent">#FF4081</color> 
</resources> 

styles.xml

<resources> 

    <!-- Base application theme. --> 
    <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> 

    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
    </style> 

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

Edit: Ok, eine interessante Lösung gefunden, es wirklich verstehen wollen, nicht nur darauf vertrauen. Auch könnte es langfristig nicht die beste Antwort sein.

Wie auch immer, auf die Basisanwendung Thema (AppTheme) in styles.xml, habe ich die folgende Zeile:

<item name="android:windowBackground">@color/colorPrimaryDark</item> 

Es funktionierte, machte es den Hintergrund all dessen, was ich nicht speziell eine Farbe zugewiesen haben diese Farbe. Aber es hat auch die Statusleiste farbig gemacht, also ging ich durch und fügte meinen eigenen Hintergründen andere Dinge hinzu, um sie zu beheben.

Ich denke, das ist nicht die ideale Lösung, und würde gerne mehr Feedback im Allgemeinen. Auch ohne diese Zeile war die Statusleiste farbig. Ich habe keine Ahnung, was ich getan habe, um es überhaupt zu brechen.

Danke.

Edit: Hier ist der Aktivitätscode. Vielen Dank.

import android.content.Intent; 
import android.os.Bundle; 
import android.support.design.widget.TabLayout; 
import android.support.v4.view.ViewPager; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.Menu; 
import android.view.MenuItem; 

import io.craigmiller160.contacts5.R; 
import io.craigmiller160.contacts5.fragments.ContactsGroupsFragmentPage; 
import io.craigmiller160.contacts5.fragments.ContactsListFragmentPage; 
import io.craigmiller160.contacts5.fragments.ContactsTabsPagerAdapter; 

public class ContactsActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_contacts); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.contactsActivityToolbar); 
     setSupportActionBar(toolbar); 

     ViewPager viewPager = (ViewPager) findViewById(R.id.contactsTabsViewPager); 

     ContactsTabsPagerAdapter adapter = new ContactsTabsPagerAdapter(getSupportFragmentManager()); 
     adapter.addFragmentPage(new ContactsListFragmentPage(), "Contacts"); 
     adapter.addFragmentPage(new ContactsGroupsFragmentPage(), "Groups"); 
     viewPager.setAdapter(adapter); 

     TabLayout tabLayout = (TabLayout) findViewById(R.id.contactsActivityTabs); 
     tabLayout.setupWithViewPager(viewPager); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.displaySettings) { 
      Intent intent = new Intent(this, DisplaySettingsActivity.class); 
      startActivity(intent); 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 
+0

Nur neugierig. Ihre Aktivität erweitert AppCompatActivity, richtig? – DavidH

+0

Können Sie Ihren Manifest- und Aktivitätscode auch posten? Außerdem sollten Sie 'android: statusBarColor =" @ color/colorPrimaryDark "' aus Ihrem Layout-XML entfernen. – DavidH

+0

'android: passtSystemWindows =" true "' ist verdächtig. Es wird verwendet, um die Aktivität oder Komponenten unter der Statusleiste in Kombination mit einer transparenten Statusleiste zu zeichnen. Wenn Sie Teile des Codes von irgendwo kopiert haben, haben Sie möglicherweise etwas übersehen, das Ihr Problem verursacht. Also, wie gesagt, poste bitte deinen Aktivitätscode oder zumindest die Teile, die du für relevant hältst. – DavidH

Antwort

2

Versuchen Sie dies als Ihr 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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".activities.ContactsActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/contactsActivityAppbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

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

     <android.support.design.widget.TabLayout 
      android:id="@+id/contactsActivityTabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabIndicatorColor="@android:color/white" 
      android:scrollbarStyle="insideOverlay" 
      android:paddingBottom="1dp" 
      android:background="?attr/colorPrimary"/> 

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

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

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

Ich denke, Sie haben das Thema mehrmals festgelegt und es ist verwirrend.

Wenn alles richtig gemacht wird, erhält der Status Balken seine Farbe von colorPrimaryDark.

0

Ich hatte genau dieses Problem. Ich reparierte sie durch die App Thema Ändern der NoActionBar AppCompat Stil zu erweitern:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/primary</item> 
    <item name="colorPrimaryDark">@color/primary_dark</item> 
    <item name="colorAccent">@color/accent</item> 
    <item name="android:windowBackground">@color/alabaster</item> 
</style> 

Meine Aktivität Layout ist:

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:ignore="MergeRootFrame"> 

<android.widget.RelativeLayout 
    android:id="@+id/chat_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    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.v7.widget.Toolbar> 
</android.support.design.widget.AppBarLayout> 

Wo die RelativeLayout ein Fragment hält, die nur eine RecyclerView hat in einem RelativeLayout. Also entferne die android: statusBarColor = "@ color/colorPrimaryDark" und fitSystemWindow xml Zeilen und ändere dein Theme und ich denke das sollte funktionieren.

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

Sie werden diese Codezeile in values/styles/styles.xml(v21) sehen. Entfernen Sie es und das löst das Problem

3

Sie können dies erreichen. Gehen Sie zu Ihrem style.xml (v21) und nur die Farbe ändern

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

Ich hoffe, dass dies Ihr Problem lösen wird.

+0

wenn das für dich funktioniert dann markiere es richtig damit es auch anderen helfen kann. –

1

Ich kann nicht sagen, dass ich in diese in jedem Detail haben gesucht, aber keiner der anderen Antworten haben vorgeschlagen, „windowDrawsSystemBarBackgrounds“ - die, ohne zu funktionieren scheint explizit die Statusleiste Farben einzustellen. Somit Werte-v21/styles.xml:

<resources> 
    <style name="AppTheme.NoActionBar"> 
     <item name="windowActionBar">false</item> 
     <item name="windowNoTitle">true</item> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
    </style> 
</resources> 
0

In styles.xml,

diese ersetzen:

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

mit:

<style name="NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

und machen entsprechende Änderungen in Manifest.xml

Verwandte Themen