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>
  • 相关阅读:
    阿里云服务器配置
    linux 环境变量问题
    docker 常用操作
    docker 安装的nginx 的默认配置
    camera开发相关
    Ubuntu下使用Git
    Java web项目实现多附件上传
    Java web项目实现上传图片及时预览
    SQL Server游标【转】
    SQL Server游标的使用【转】
  • 原文地址:https://www.cnblogs.com/cnman/p/9897866.html
Copyright © 2011-2022 走看看