zoukankan      html  css  js  c++  java
  • 设置状态栏透明

    方法一:通过修改主题来设置状态栏变透明,需要在values、values-v19、values-v21目录下分别创建相应的主题。

    //values
    <style name="TranslucentTheme" parent="AppTheme">
    </style>
    
    //values-v19
    <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowTranslucentStatus">true</item>
            <item name="android:windowTranslucentNavigation">false</item>
    </style>
    
    //values-v21
    <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
            <item name="android:windowTranslucentStatus">true</item>
            <item name="android:windowTranslucentNavigation">false</item>
            <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

       <style name="Theme.AppCompat.Light.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>

     方法二: 通过代码设置

        private void setStatusBarTransparent() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
                View decorView = getWindow().getDecorView();
                int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
                decorView.setSystemUiVisibility(option);
                getWindow().setStatusBarColor(Color.TRANSPARENT);
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
                WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
                localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
            }
        }

    参考: 

    Android 状态栏着色实践

  • 相关阅读:
    07_schema的元素和属性的定义
    06_schema的命名空间
    05_dtd
    04_SOA的分析
    03_wsdl和soap
    02_wsimport的使用
    01快速实现一个基于Jws的Webservice项目
    自定义函数基础-预设值问题
    自定义函数基础-返回值,单值、多值
    自定义函数基础
  • 原文地址:https://www.cnblogs.com/huyang011/p/7484077.html
Copyright © 2011-2022 走看看