How can I make the status bar white with black icons?

耗尽温柔 提交于 2019-12-17 17:47:09

问题


I want to change the colour of the status bar for my app so that it's white with black icons (instead of the default black with white icons). Is there any way of doing this?


回答1:


With Android M (api level 23) you can achieve this from theme with android:windowLightStatusBar attribute.

Edit :

Just as Pdroid mentioned, this can also be achieved programatically:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); 



回答2:


It is possible to make the white status bar with grey icons e.g. this way for SDK >= 23 (see docs):

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowLightStatusBar">true</item>
</style>

in your styles.xml and set the colorPrimary to white or programmatically:

getWindow().setStatusBarColor(Color.WHITE);



回答3:


Just added to my activity on Kotlin:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                window.decorView.systemUiVisibility =View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
                window.statusBarColor = Color.WHITE
            }



回答4:


just add this to you style

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>

set android:windowDrawsSystemBarBackgrounds to true*. This is a flag whose description is given below:

Flag indicating whether this Window is responsible for drawing the background for the system bars. If true and the window is not floating, the system bars are drawn with a transparent background and the corresponding areas in this window are filled with the colors specified in {@link android.R.attr#statusBarColor} and {@link android.R.attr#navigationBarColor}. Corresponds to {@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS}.




回答5:


No such way to this unless if you have a control of the whole rom to customize that manually. What i suggest you to do is, use a light gray color for the status bar color through your theme like the google drive does.

Edit: please refer to @Wrekcker answer as this changed in android M.




回答6:


I had the same issue.

I noticed that when I use normal layout like RelativeLayout it doesn't work. But when I switched to that come from support library like CordinatorLayout it has finally started to work. Try this.

  <?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:fitsSystemWindows="true"
        tools:context=".Activities.Activity">


        <android.support.v7.widget.Toolbar
            android:id="@+id/tb_activity"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />


    </android.support.design.widget.CoordinatorLayout>

<********* BELOW OTHERS ATTRIBUTES ************>

styles

<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" parent="AppTheme">
    <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" />

And in the manifest

<activity
            android:name=".Activities.MyActivity"
            android:label="Activity"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>


来源:https://stackoverflow.com/questions/27623627/how-can-i-make-the-status-bar-white-with-black-icons

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!