6

Wait, it is not a duplicate

A similar question has been asked here, but not addressing dark-text status bar.

What I want to do

I want to achieve 3 things at the same time:

  1. Transparent status bar (Not hiding it!)
  2. Dark-text status bar
  3. Opaque (or black) navigation bar (which does not let activity content inflate underneath it)

What I have tried

The solution

            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

can only achieve 1 and 3;

The solution here can only achieve 1 and 2;

And the solution here can only achieve 2 and 3....

The Question

So is there a way to achieve all 1, 2 an 3?!

Sira Lam
  • 4,412
  • 24
  • 53
  • `The solution here can only achieve 1 and 2` But in that answer navigation bar is transparent and activity's content is drawn beneath of it. Whereas you have told that you want `Opaque (or black) navigation bar (which does not let activity content inflate underneath it)`. You requirement is not quite clear. – azizbekian May 25 '18 at 08:20
  • My requirement is clear and you have already got it, I want opaque navigation bar but that answer can only achieve transparent navigation bar. Where is the contradiction? – Sira Lam May 25 '18 at 08:21
  • Now I see, my fault – azizbekian May 25 '18 at 09:25
  • @azizbekian Don't mind, your answer worked like a charm! – Sira Lam May 25 '18 at 09:34

1 Answers1

7

Inside styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:navigationBarColor">@android:color/black</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

In activity's onCreate():

override fun onCreate(savedInstanceState: Bundle?) {
  window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
  super.onCreate(savedInstanceState)
  setContentView(R.layout.activity_main)
}

Will result in this:

azizbekian
  • 53,978
  • 11
  • 145
  • 225