2016-10-22 157 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