初识--沉浸式状态栏

最近在各大论坛上总能看到这个词“沉浸式状态栏”,在网上看了一下相关的知识很多,动手敲了一下,很不错。留个博客记录一下吧~
该效果只能应用在4.4以上版本~

protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // 设置沉浸式状态栏         
        if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT) {
            WindowManager.LayoutParams localLayoutParams
             = getWindow().getAttributes();
            localLayoutParams.flags =
               (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS 
                | localLayoutParams.flags);
            if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
                drawerLayout.setFitsSystemWindows(true);
                drawerLayout.setClipToPadding(false);
            }
        }
    }

加入该代码后,就能实现沉浸式状态栏。

猜你喜欢

转载自blog.csdn.net/dong40407/article/details/58607317