• 72、android状态栏一体化,状态栏改变颜色


         只能在4.4以上版本使用。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#6699ff"
        android:clipToPadding="true"
        android:fitsSystemWindows="true"
        android:orientation="vertical" >
    
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:orientation="vertical" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="标题"
                android:textColor="#ffffff"
                android:textSize="20sp" />
        </RelativeLayout>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:gravity="center"
            android:orientation="vertical" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Hello World"
                android:textColor="#000000"
                android:textSize="28sp"
                android:textStyle="italic" />
        </LinearLayout>
    
    </LinearLayout>
    android:clipToPadding="true"  
    clipToPadding:控件的绘制区域是否在padding里面, 值为true时padding那么绘制的区域就不包括padding区域; 
    android:fitsSystemWindows="true"
    设置应用布局时是否考虑系统窗口布局;如果为true,将调整系统窗口布局以适应你自定义的布局。比如系统有状态栏,应用也有状态栏时。
    看你这个布局代码,恰恰是在定义标题栏样式,所以用到这行代码了。

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.activity_main);
            //判断当前SDK版本号,如果是4.4以上,就是支持沉浸式状态栏的
            if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            }
        }
    
    
    


  • 相关阅读:
    《sql必知必会》笔记
    HTTP抓包与调试(Firefox插件)
    软件测试方法和技术实践(学习笔记)
    java基础(一章)
    java基础(二章)
    final关键字(最终的)
    算术运算符与控制台输入
    eclipse自动补全的设置
    Java关于Properties用法的总结(一)
    使用Struts2标签遍历集合
  • 原文地址:https://www.cnblogs.com/androidsj/p/5121606.html
Copyright © 2020-2023  润新知