无法将状态栏设置为透明

时间:2019-07-24 14:25:54

标签: android material-design android-theme android-statusbar

我正在尝试将BNavigationBar都设为StatusBar,然后使用transparent来调整视图。

我现在可以使用透明的windowInsets来正确应用NavigationBar,但是我不能更改windowInsets的颜色。我已经尝试过在网上找到的每种组合,但是唯一有效的组合是使用StatusBar,这会导致FLAG_LAYOUT_NO_LIMITSwindowInset返回0(这是“很好,因为我使用的是systemWindowInsetBottom

BottomAppBar为纯白色时,StatusBar返回正确数量的像素,并且视图的布局正确,但是当我滚动windowInset.systemWindowInsetTop时它消失在RecyclerView后面。

这是我当前的设置,我真的需要另一双眼睛来发现错误。

MainActivity

StatusBar

主题

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setWindowBehindSystemBars()
    colorizeStatusBar()
    setContentView(R.layout.activity_main)
}

private fun setWindowBehindSystemBars() {
    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}

private fun colorizeStatusBar() {
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
    window.statusBarColor = ContextCompat.getColor(this, R.color.transparent)
}

编辑

我尝试将<style name="BaseTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <!-- other attributes, all related to color --> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="android:navigationBarColor">@color/transparent</item> </style> 设置为蓝色,当应用程序打开时,我可以在短暂的时间内看到StatusBar后面的蓝色,因此我认为这之后将颜色重新设置为白色。

0 个答案:

没有答案
相关问题