How to change system navigation bar color

后端 未结 8 1690
故里飘歌
故里飘歌 2020-12-08 02:17

In guidelines of Android 5.0, the navigation bar seems customizable: http://www.google.com/design/spec/layout/structure.html#structure-system-bars

H

相关标签:
8条回答
  • 2020-12-08 02:24

    add this line in your v-21/style

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@android:color/black</item>
    </style>
    

    0 讨论(0)
  • 2020-12-08 02:28

    the navigation bar is not supposed to be colored

    When you customize the navigation and status bars, either make them both transparent or modify only the status bar. The navigation bar should remain black in all other cases.

    (source https://developer.android.com/training/material/theme.html )

    BUT, you can use this library to achieve what you want :) https://github.com/jgilfelt/SystemBarTint

    0 讨论(0)
  • 2020-12-08 02:28
     getWindow().setNavigationBarColor(ContextCompat.getColor(MainActivity.this,R.color.colorPrimary)); //setting bar color   
     getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); //additional setting items to be black if using white ui  
    
    0 讨论(0)
  • 2020-12-08 02:41
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setNavigationBarColor(getResources().getColor(R.color.colorWhite));
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); //For setting material color into black of the navigation bar
        }
    

    Use this one if your app's API level is greater than 23

    getWindow().setNavigationBarColor(ContextCompat.getColor(MainActivity.this, R.color.colorWhite));
            getWindow().getDecorView().setSystemUiVisibility(SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
    

    May this code will not work for API level 30. Because " SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR" is deprecated in API level 30. Check this out: https://developer.android.com/reference/android/view/View#SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR

    0 讨论(0)
  • 2020-12-08 02:46

    use this simple line to change the navigation bar color according to your screen background color

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.any_color));
            }
    

    else you can use the light style for the navigation bar

    <item name="android:navigationBarColor">@android:color/white</item>
    
    0 讨论(0)
  • 2020-12-08 02:47

    Starting from API 27, it is now possible to use the light style of the navigation bar:

    <item name="android:navigationBarColor">@android:color/white</item>
    <item name="android:windowLightNavigationBar">true</item>
    

    From the documentation:

    windowLightNavigationBar

    If set, the navigation bar will be drawn such that it is compatible with a light navigation bar background.

    For this to take effect, the window must be drawing the system bar backgrounds with windowDrawsSystemBarBackgrounds and the navigation bar must not have been requested to be translucent with windowTranslucentNavigation. Corresponds to setting SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR on the decor view.

    0 讨论(0)
提交回复
热议问题