Search code examples
androidandroid-5.0-lollipopstatusbarandroid-appcompatandroid-4.4-kitkat

Android development - Status Bar not showing on pre Lollipop (AppCompat)


I'm developing my app using appcompat v21.0.3 and testing on API 21 android ver 5.0.1.Today I decided to test the application on the tablet with Android 4.4.2, and everything would be ok but I did notice that the status bar has become transparent and dropped to toolbar. I have attached pictures and i hope for your help. P.S Sorry for my english, i used google translator to make this text :)

It looks like this https://i.sstatic.net/W4Sve.png But should look like this https://i.sstatic.net/fR1B7.jpg


Solution

  • In your manfest replace

    android:theme="@style/AppTheme"
    

    with

    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    

    Use the below code the your Main Activity to assign color to status bar.

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Window window = this.getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.setStatusBarColor(this.getResources().getColor(R.color.main_red_dark));
            }
    

    Of course, this is just one way. I am not 100% sure, where your are actually changing the code of status bar. It has to be done.