zoukankan      html  css  js  c++  java
  • Android状态栏和导航栏

    1.隐藏状态栏或导航栏

            View decordView = getWindow().getDecorView();
            /*SYSTEM_UI_FLAG_HIDE_NAVIGATION和SYSTEM_UI_FLAG_FULLSCREEN 分别代表隐藏导航栏和状态栏
            * SYSTEM_UI_FLAG_IMMERSIVE_STICKY 沉浸式效果*/
            decordView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
            getSupportActionBar().hide();
        }
    

    2. 使状态栏透明

    1.通过代码设置
          View decordView = getWindow().getDecorView();
            decordView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                );
            if (Build.VERSION.SDK_INT >= 21) {
                getWindow().setStatusBarColor(Color.GREEN);
                getWindow().setNavigationBarColor(Color.GREEN);
     
            } 
    

     ps:    getSupportActionBar().hide();不要调用hide而是 在xml中的style中直接使用Theme.AppCompat.Light.NoActionBar

    并且在layout中设置android:fitsSystemWindows="true" 可以让布局布局在状态栏下面而不是覆盖状态栏

    2.通过主题设置

    api>=21

        
    <style name="TranslucentStatus" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:statusBarColor">@android:color/transparent</item> <item name="android:windowTranslucentStatus">false</item><!--如果为true导航栏为半透明--> <item name="android:windowTranslucentNavigation">true</item> </style>

    api 19

     <style name="TranslucentStatus" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowTranslucentStatus">true</item
    </style>
  • 相关阅读:
    [leetcode]Set Matrix Zeroes
    [leetcode]Sort Colors
    [leetcode]Combinations
    [leetcode]Subsets
    [leetcode]Search a 2D Matrix
    [leetcode]Best Time to Buy and Sell Stock III
    [leetcode]Best Time to Buy and Sell Stock II
    [leetcode]Best Time to Buy and Sell Stock
    半平面交 (poj 1279(第一道半平面NlogN)完整注释 )
    hdu 4277 USACO ORZ (Dfs)
  • 原文地址:https://www.cnblogs.com/cnman/p/9897866.html
Copyright © 2011-2022 走看看