android-cn / android-discuss

Android 问题交流讨论坛, 微信公众号:codekk, 网站:
https://github.com/android-cn/android-discuss/issues
Apache License 2.0
4.08k stars 535 forks source link

[问答]状态栏完全透明设置 #590

Closed shucc closed 7 years ago

shucc commented 7 years ago

我希望实现的效果是类似微博,上方的状态栏是完全透明的

sina

目前实现的效果如下(6.0手机上效果),并不是完全透明的

status

目前的实现代码是在values-v19/styles.xml中设置

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>

    <style name="SplashTheme" parent="AppTheme">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowBackground">@drawable/bg_splash</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

请问需要怎样修改才能改成和微博的完全透明状态栏一样? 已解决,5.0以上在代码中设置: if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); }

Bakumon commented 7 years ago

接近原生系统可能都是半透明效果,你可以在这个手机上安装微博验证下效果

shucc commented 7 years ago

@Bakumon 我测试的就是nexus 5,微博上显示的的确是全透明的

Bakumon commented 7 years ago

@shucc https://github.com/laobie/StatusBarUtil 试试这个吧