android中让通知栏和标题栏的颜色一样

来源:互联网 发布:www.gvlib video.php 编辑:程序博客网 时间:2024/05/22 06:35

其实就是沉浸模式,在activity中的onCreate方法中,调用如下两个方法:

//沉浸模式public void setTransluteWindow(){    //设置状态栏透明    Window window = getWindow();    window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);    // window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}public static int getStatusBarHeight(Context context) {    int result = 0;    int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen",            "android");    if (resourceId > 0) {        result = context.getResources().getDimensionPixelSize(resourceId);    }    return result;}

0 0