1

I want to have a transparent statusBar in the light style like this

enter image description here

I tried this code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        this.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 = ContextCompat.getColor(applicationContext, R.color.transparent)
        }
}

but I can't add decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR for change text color of statusBar because I add SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

after that I used setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) in this answer but my activity go under the back button like this

enter image description here

mohsen
  • 1,065
  • 16
  • 24
  • I think it is going behind the back button bar because of this `decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN`. Do you want the back button bar or do youwant your app to be full screen always? – The Bat Dec 09 '19 at 10:58
  • 1
    This is the navigation bar, not the status bar – Tim Dec 09 '19 at 11:00
  • NO, I want my app to stay above the back button @TheBat – mohsen Dec 09 '19 at 11:12
  • I think if you remove the `SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN` it should just work fine – The Bat Dec 09 '19 at 11:13
  • Ok I know the second picture is a navigation bar but when I want to transparent my status bar, my navigation bar go on my app @Tim – mohsen Dec 09 '19 at 11:15
  • It works fine but when I add ```decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR``` instead of ```decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN``` it doesn't work @TheBat – mohsen Dec 09 '19 at 11:18
  • @mohsen did you check this https://developer.android.com/guide/navigation/gesturenav#edge-to-edge. In case you are looking for edge to edge content!. – Raghunandan Dec 09 '19 at 11:21
  • Yes but unfortunately go under the back button @Raghunandan – mohsen Dec 09 '19 at 11:31
  • you need to set the flags properly and it should work – Raghunandan Dec 09 '19 at 11:34
  • which OS version are you testing on, because, I just tried it on my app and works fine – The Bat Dec 09 '19 at 11:41
  • Nexus 5x - Android 8.1.0 @TheBat – mohsen Dec 09 '19 at 11:45
  • do you set this ```SYSTEM_UI_FLAG_LIGHT_STATUS_BAR``` @TheBat – mohsen Dec 09 '19 at 11:46
  • No, I simply added the first code block that you have posted, now I added `setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS` and now m y app also goes under the navigation bar – The Bat Dec 09 '19 at 11:48

2 Answers2

2

Try out this code

  val winParams = window?.getAttributes()
                winParams?.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                window?.setAttributes(winParams)
                window?.getDecorView()
                    ?.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
mohsen
  • 1,065
  • 16
  • 24
Jai Khambhayta
  • 4,198
  • 2
  • 22
  • 29
0

This for go back to the dark theme

val winParams = window?.attributes
            winParams?.flags = -2139029248
            window?.attributes = winParams
            window?.decorView?.systemUiVisibility = 0
            window.statusBarColor = ContextCompat.getColor(this, R.color.colorPrimaryDark)
mohsen
  • 1,065
  • 16
  • 24