博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android沉浸式状态栏(非常简单)
阅读量:4205 次
发布时间:2019-05-26

本文共 949 字,大约阅读时间需要 3 分钟。

废话不多说直接上代码

在onCreate() 方法里面

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {    int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;    int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {        Window window = getWindow();        WindowManager.LayoutParams attributes = window.getAttributes();        attributes.flags |= flagTranslucentNavigation;        window.setAttributes(attributes);        getWindow().setStatusBarColor(Color.TRANSPARENT);    } else {        Window window = getWindow();        WindowManager.LayoutParams attributes = window.getAttributes();        attributes.flags |= flagTranslucentStatus | flagTranslucentNavigation;        window.setAttributes(attributes);    }}

 这样沉浸式状态栏就搞定了

当然不要忘记styles里面改成NO

 这样状态栏虽然OK了但是你会发现toobar与状态栏重叠了,这时咱们就需要在布局中添加:

android:fitsSystemWindows="true"

这样就完成沉浸式状态栏 

转载地址:http://hutli.baihongyu.com/

你可能感兴趣的文章