0

I am having problem with status bar color when I use android:fitsSystemWindows="false"

It becomes transparent. I dont want that to happen. I want to it have colorPrimaryDark as its color.

I have to set this as false because I am using a FrameLayout in main layout so that I can inflate a overlay fragment, When android:fitsSystemWindows="false" is set true the overlay occupies whole screen, I dont want that to happen with overlay fragment.

my activity_main looks like this.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/layout_bg_white"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:openDrawer="start"
tools:context="com.example.tabstrial2.MainActivity">

<RelativeLayout
    android:id="@+id/main_layout_of_app"
    android:layout_width="match_parent"
    android:layout_height="match_parent">




</RelativeLayout>


<FrameLayout
    android:id="@+id/overlay_fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="56dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="119dp" />

</android.support.v4.widget.DrawerLayout>

style.xml looks like this.

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#500347</item>
    <item name="colorPrimaryDark">#862b7b</item>
    <item name="colorAccent">#1a2fcf</item>
    <item name="android:textColor">#ffffff</item>
    <item name="colorControlHighlight">#fff</item>
    <item name="colorControlActivated">@android:color/holo_green_dark</item>
    <item name="colorControlNormal">#fff</item>   <!-- normal border color      change as you wish -->
    <item name="colorButtonNormal">#500347</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay"      parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AppTheme.Picker" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:textColorPrimary">@android:color/white</item>
</style>

<!--<style name="AppTheme.CheckBox" parent="Theme.AppCompat.Light.NoActionBar">-->
<!--<item name="android:colorAccent">@android:color/white</item>-->
<!--</style>-->

<style name="MyCheckBox" parent="Theme.AppCompat.NoActionBar">
    <item name="colorControlNormal">#fff
    </item>   <!-- normal border color change as you wish -->
    <item name="colorControlActivated">#fff</item> <!-- activated color change as you wish -->
    <item name="android:textColor">#FFFF3F3C</item> <!-- checkbox text color -->
</style>

3
  • 1
    show your theme used for the activity Commented Oct 13, 2016 at 13:41
  • @MujammilAhamed , Added style.xml in Question, please have a look. Commented Oct 13, 2016 at 13:50
  • just follow this tutorial (androidhive.info/2015/04/… ), may be it will help you.. Commented Oct 13, 2016 at 14:11

2 Answers 2

2

In your Activity below the setcontentview(...)

Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// finally change the color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.setStatusBarColor(Color.parseColor("#c2212a"));
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. What will happen if android version is less than LOLLIPOP? what will be color of status bar then? Sorry I would have checked myself, but I cant run emulator on my PC configuration.
@BhushanBabar try to install emulator working with LOLLIPOP+, and if the version is less then LOLLIPOP the color will be black, the default color.
thanks for sharing @Ali Taouni .. i checked many answers this is very clear one .. stackoverflow.com/questions/42968587/… please check this if you can
0

You can try to set the status bar color explicit

<item name="android:statusBarColor">@color/color_primary_dark</item>

or set the translucent status to false

<item name="android:windowTranslucentStatus">false</item> 

2 Comments

try <item name="android:windowTranslucentStatus">false</item>
Nope, again its valid only above 19 API. Ali Taouni's answer worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.