Android Completely transparent Status Bar?

前端 未结 28 2758
旧时难觅i
旧时难觅i 2020-11-22 14:10

I\'ve searched the documentation but only found this: Link. Which is used to make the bar translucent? What I\'m trying to do is to make t

28条回答
  •  死守一世寂寞
    2020-11-22 14:30

    I found fiddling with styles.xml and activity to be too cumbersome hence created a common utility method which has below options set

    Java

    Window window = getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    window.setStatusBarColor(Color.TRANSPARENT);
    

    Kotlin DSL

    activity.window.apply {
        clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        statusBarColor = Color.TRANSPARENT
    }
    

    And that's all it took to achieve transparent status bar. Hope this helps.

提交回复
热议问题