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);
}
}
Nur neugierig. Ihre Aktivität erweitert AppCompatActivity, richtig? – DavidH
Können Sie Ihren Manifest- und Aktivitätscode auch posten? Außerdem sollten Sie 'android: statusBarColor =" @ color/colorPrimaryDark "' aus Ihrem Layout-XML entfernen. – DavidH
'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