由於某種原因,狀態欄現在變成了白色。或者說,一個白色的,另一個白色的圖標可以在明亮的背景中隱約看到。這是錯誤的,因爲我的appbarlayout使用藍色作爲它的顏色。直到現在,這一直工作正常,我不知道我做了什麼導致這一點。我試過手動將statusBarColor設置爲colorPrimaryDark(#0277bd),但它不起作用。Android:狀態欄爲白色
我只是不知道爲什麼這是發生在第一個地方。我正在粘貼我的活動的layout.xml,也許有人可以告訴我我在這裏做錯了什麼。
的幾個注意事項:
使用的主題還沒有從它們的默認值,這是使用原色設置改變。我將這些改成了我想要的正確的藍色陰影,但是當我做了這些改變時,一切都奏效了。
我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>
編輯:好吧,發現了一個有趣的解決方案,真的想了解它,不只是依靠它。另外,它可能不是長期的最佳答案。
無論如何,在styles.xml基本應用程序的主題(AppTheme),添加以下行:
<item name="android:windowBackground">@color/colorPrimaryDark</item>
它的工作,這讓一切的背景下,我並沒有特別指定顏色那種顏色。但它也使得狀態欄變成了彩色,所以我通過了並將我自己的背景添加到其他的東西來修復它們。
儘管如此,我覺得這不是理想的解決方案,只是希望更多的反饋。此外,即使沒有這一行,它正在着色狀態欄就好了。我不知道我是如何打破它的。
謝謝。
編輯:這裏是活動代碼。謝謝。
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);
}
}
只是好奇。您的活動擴展了AppCompatActivity,對吧? – DavidH
你可以發佈你的Manifest和Activity代碼嗎?此外,你應該從layout xml中移除android:statusBarColor =「@ color/colorPrimaryDark」。 – DavidH
'android:fitsSystemWindows =「true」'是可疑的。它用於繪製狀態欄下的Activity或組件,並與透明的狀態欄結合使用。如果您從某處複製了部分代碼,則可能錯過了導致問題的一些內容。所以,正如我所說,請張貼您的活動代碼,或者至少只是您認爲相關的部分。 – DavidH