Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中设置状态栏的背景色?_Android - Fatal编程技术网

如何在android中设置状态栏的背景色?

如何在android中设置状态栏的背景色?,android,Android,有没有办法设置状态栏的背景色?我希望动作栏的背景色与状态栏保持一致 棒棒糖中的colorPrimaryDark表示状态栏的颜色 <style name="BaseAppTheme" parent="Theme.AppCompat.Light"> <item name="colorPrimary">@color/main_theme</item> <item name="colorPrimaryDark">@color/main_th

有没有办法设置状态栏的背景色?我希望动作栏的背景色与状态栏保持一致

棒棒糖中的colorPrimaryDark表示状态栏的颜色

<style name="BaseAppTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">@color/main_theme</item>
    <item name="colorPrimaryDark">@color/main_theme_dark</item>
    <item name="colorAccent">@color/main_theme_accent</item>
    <item name="android:textColor">@color/main_theme_text_color</item>
</style>
在爪哇

        getWindow().setStatusBarColor(Color.argb(40, 0, 0, 0));

这只有在android 5.0+上才可能实现,您只需使用正确的主题和参数即可

创建或修改themes.xml,并在manifest中将主题应用于应用程序,当然,您还必须定义自己的颜色

values/themes.xml:

        getWindow().setStatusBarColor(Color.argb(40, 0, 0, 0));
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name=”colorPrimary”>@color/my_awesome_color</item>

    <!-- colorPrimaryDark is used for the status bar -->
    <item name=”colorPrimaryDark”>@color/my_awesome_darker_color</item>

    <!-- colorAccent is used as the default value for colorControlActivated,
         which is used to tint widgets -->
    <item name=”colorAccent”>@color/accent</item>

    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight, and colorSwitchThumbNormal. -->

</style>