Statusbarcolor无法正常工作

时间:2016-05-11 12:31:00

标签: android xml ui-design

statusbarcolor仅适用于具有导航抽屉的那些活动。其余的活动都有白色状态栏颜色。

请任何人建议我应该为此做些什么?see image 1st:this is the second image in which status barcolor not working.

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>

默认情况下,状态栏颜色采用colorPrimaryDark。我正在尝试使用改变 <item name="android:statusBarColor">@color/ColorPrimary</item>

但它没有用。

  

<style name="Theme.Astrosage" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:actionBarItemBackground">@drawable/selectable_background_astrosage</item>
    <item name="android:spinnerStyle">@style/Base.Widget.AppCompat.Spinner.Underlined</item>
    <!--<item name="colorControlNormal">@color/ColorPrimary</item>-->
    <item name="android:popupMenuStyle">@style/PopupMenu.Astrosage</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Astrosage</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Astrosage</item>
    <item name="android:actionDropDownStyle">@style/DropDownNav.Astrosage</item>
    <item name="android:actionBarStyle">@style/ActionBar.Solid.Astrosage</item>
    <item name="android:actionModeBackground">@drawable/cab_background_top_astrosage</item>
    <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_astrosage</item>
    <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Astrosage</item>
    <item name="android:progressBarStyleHorizontal">@style/ProgressBarHukumTheme</item>
    <!-- Light.DarkActionBar specific
    <item name="android:editTextStyle">@style/Theme.App.Base</item>-->
    <item name="android:actionBarWidgetTheme">@style/Theme.Astrosage.Widget</item>
    <item name="colorPrimary">@color/ColorPrimary</item>
    <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
    <!--<item name="android:statusBarColor">@color/ColorPrimary</item>-->
    <item name="colorAccent">@color/ColorPrimary</item>
    <item name="android:colorControlHighlight">@color/ColorPrimary</item>
    <item name="android:indeterminate">true</item>
    <item name="android:indeterminateTint">@color/ColorPrimaryDark</item>
    <item name="android:indeterminateTintMode">src_in</item>
    <!--<item name="android:colorAccent">@color/ColorPrimary</item>-->
    <item name="android:textViewStyle">@style/custom_textview</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowTranslucentStatus">true</item>

    <item name="windowActionModeOverlay">true</item>
    <item name="android:fitsSystemWindows">true</item>

</style>

<style name="custom_textview" parent="@style/Base.TextAppearance.AppCompat">
    <item name="android:textAllCaps">false</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textColor">@color/text_color</item>
</style>

<style name="custom_button" parent="android:Widget.Button">
    <item name="android:textAllCaps">false</item>
    <item name="android:textStyle">normal</item>
</style>

<style name="Theme.App.Base" parent="android:Widget.EditText">
    <item name="colorControlNormal">@color/ColorPrimary</item>
    <item name="android:textColorSecondary">@color/ColorPrimary</item>
    <item name="colorControlActivated">@color/ColorPrimary</item>
    <item name="colorControlHighlight">@color/ColorPrimary</item>
    <item name="android:textSize">16sp</item>
    <item name="android:cursorVisible">true</item>
    <item name="android:textSelectHandle">@drawable/ic_keyboard_arrow_up_black</item>
    <item name="android:textSelectHandleLeft">@drawable/ic_keyboard_arrow_left_black</item>
    <item name="android:textSelectHandleRight">@drawable/ic_keyboard_arrow_right_black</item>
    <item name="android:textCursorDrawable">@drawable/custom_cursor_file</item>
    <item name="android:textColorHighlight">@color/ColorPrimary</item>
    <!--<item name="android:textColorHint">@color/ColorPrimary</item>-->
    <!--<item name="android:backgroundTint">@color/ColorPrimary</item>-->
</style>

<style name="ActionBar.Solid.Astrosage" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/ab_background_textured_astrosage</item>
    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_astrosage</item>
    <item name="android:backgroundSplit">@drawable/ab_background_textured_astrosage</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Astrosage</item>
</style>

<style name="ActionBar.Transparent.Astrosage" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@drawable/ab_transparent_astrosage</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Astrosage</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Astrosage.Widget" parent="@style/Theme.AppCompat">
    <item name="android:popupMenuStyle">@style/PopupMenu.Astrosage</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Astrosage</item>
</style>

<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
    <item name="android:colorAccent">@color/ColorPrimaryDark</item>
    <item name="android:colorPrimaryDark">@color/ColorPrimaryDark</item>
    <item name="android:colorPrimary">@color/ColorPrimaryDark</item>
</style>
<style name="MyCheckBox" parent="Theme.AppCompat.Light">
    <item name="colorControlNormal">@color/ColorPrimaryDark</item>
    <item name="colorControlActivated">@color/ColorPrimaryDark</item>
</style>

<style name="buttonstyle" parent="Theme.AppCompat.Light">
    <item name="android:textColor">@color/white</item>
    <item name="android:colorControlHighlight">@color/ColorPrimary</item>
    <item name="android:colorButtonNormal">@color/ColorPrimaryDark</item>
    <item name="android:colorAccent">@color/ColorPrimary</item>
    <item name="android:layout_marginTop">@dimen/standard_top_margin</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">@dimen/button_height</item>

    <item name="android:textAllCaps">false</item>
    <item name="android:textSize">18dp</item>
    <item name="android:layout_marginBottom">@dimen/buttonmarginBottom</item>
</style>
<style name="buttonstylesilverplan" parent="Theme.AppCompat.Light">
    <item name="android:textColor">@color/white</item>
    <item name="android:colorControlHighlight">@color/toolbar_color_basic_plan</item>
    <item name="android:colorButtonNormal">@color/ColorPrimary</item>
    <item name="android:colorAccent">@color/toolbar_color_basic_plan</item>
    <item name="android:layout_marginTop">@dimen/standard_top_margin</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">@dimen/button_height</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:textSize">18dp</item>
    <item name="android:layout_marginBottom">@dimen/buttonmarginBottom</item>
</style>
<style name="buttonstylebasicplan" parent="Theme.AppCompat.Light">
    <item name="android:textColor">@color/white</item>
    <item name="android:colorControlHighlight">@color/ColorPrimary</item>
    <item name="android:colorButtonNormal">@color/toolbar_color_basic_plan</item>
    <item name="android:colorAccent">@color/ColorPrimary</item>
    <item name="android:layout_marginTop">@dimen/standard_top_margin</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">@dimen/button_height</item>
    <item name="android:textAllCaps">false</item>
    <item name="android:textSize">18dp</item>
    <item name="android:layout_marginBottom">@dimen/buttonmarginBottom</item>
</style>

2 个答案:

答案 0 :(得分:0)

试试这个,

更改应用主题样式的颜色。

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@android:color/white</item>
        <item name="colorPrimaryDark">Your statusBar color</item>
        <item name="colorAccent">@color/colorAccent</item>

    </style>

或者您可以使用此更改颜色,

public void setStatusBarColor(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = activity.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(Color.RED);
        }

答案 1 :(得分:0)

你的style.xml文件中的

放了这些行

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">@color/color_primary</item>
    <item name="colorPrimaryDark">@color/color_secondary</item>
    <item name="colorAccent">@color/color_accent</item>
    <item name="android:statusBarColor">@color/color_primary</item>
</style>

在color.xml文件中

,写下这些行

 <color name="color_secondary">#(your color)</color>
 <color name="color_primary">#(your color)</color>
 <color name="color_accent">#(your color)</color>