2016-10-22 151 views
0

爲什麼我的狀態欄有這種顏色?我需要的顏色與工具欄相同(藍色)狀態欄顏色錯誤

enter image description here

styles.xml

<style name="MFB" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="windowActionModeOverlay">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
</style> 

settingsactivity.xml

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:fitsSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <include 
     android:id="@+id/toolbar" 
     layout="@layout/toolbar" /> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_below="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</RelativeLayout> 

在主要活動及其工作好吧,看:

enter image description here

我不知道什麼是錯在這裏......我所期望的是其他職位的答案,但同樣我得到了白狀態欄:/

謝謝:)和遺憾,如果它是一個noob問題

編輯

Toolbar.xml:

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:minHeight="?attr/actionBarSize" 
android:background="?attr/colorPrimary" 
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

注意:在使用 IM

"com.android.support:appcompat-v7:23.4.0" 
"com.android.support:design:23.4.0" 
+0

第一的所有指定什麼是您的設備版本,並張貼'工具欄'佈局文件如何申請? – Ironman

回答

0

所有你需要做的是設置你的主題這些屬性:

真正 真正

您的活動/容器佈局您希望透明狀態欄需要此屬性集:

android:fitsSystemWindows =「true」

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
      Window w = getWindow(); // in Activity's onCreate() for instance 
      w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); 
     } 

別人通過這個鏈接會幫助你

​​3210

希望它可以幫助別人:)。

現在我只需要讓它向後兼容。

+0

看看這個:http://i.imgur.com/30yskbb.png – ZeeRooo

1

我認爲問題一定是您沒有爲您的項目創建res/values-v21 folder。給Lollipop和上面的設備不同的風格,你必須創建values-v21文件夾在res目錄,並在那裏定義你的風格。

styles.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <style name="AppBaseTheme" parent="AppTheme"> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="android:statusBarColor">@color/blue</item> 
    </style> 

</resources> 
1
<style name="MFB" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="windowActionModeOverlay">true</item> 
    <item name="android:statusBarColor">@android:color/transparent</item> 
</style> 

改變上述的android:statusBarColor在你的風格。

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

它的工作。我希望它解決您的問題。

+0

不,因爲當導航菜單中的im時,狀態欄是完全藍色的並且應該是透明的:https://i.stack.imgur。 com/dBhcd.png – ZeeRooo

0

嘗試刪除<item name="android:statusBarColor">@android:color/transparent</item> thisline。狀態欄的顏色從colorPrimaryDark。將此顏色設置爲所需的顏色。

看到這個

enter image description here

編輯

如果你想改變狀態欄的顏色在您的應用程序的某個階段,你可以試試這個

Window window = getWindow(); 
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 
window.setStatusBarColor(YOUR_COLOR); 
+0

如果我使用 'Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(YOUR_COLOR);' 設置活動_(color.transparent)_它使用白色背景並且沒有工具欄的顏色。我的應用程序有主題引擎(不同的顏色可供選擇),我需要與主題相同顏色的狀態欄。 – ZeeRooo