9

I found a issue that affects Relative Layout height while I was trying to add color to status bar.

adding Flag affected of calculation of the relative layouts rootView's height.

private void changeStatusBarColor(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.red_e31837));
        }
    }

I have a view tree observer that help me to track height of the rootView.

private ViewTreeObserver.OnGlobalLayoutListener keyboardLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {

            int heightDiff = wrapper.getRootView().getHeight() - wrapper.getHeight();
}

int heightDiff equals to 1920 if I use FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS but if I dont use changeStatusBarColor(), int heightDiff equals to 1776 (calculates without actionbar and statusbar I guess). But Why adding this flag change calculations? Thanks in advance!

Orcun Sevsay
  • 1,310
  • 1
  • 14
  • 44
  • 1
    If you pass in that flag, the window manager gives you additional room to draw in the system bar area. You don't need to pass in that flag to set the status bar color, you just need the call to `setStatusBarColor(int)`. – alanv Apr 01 '15 at 16:47
  • 1
    @alanv Thank you I understood the reason; but if I don't use flag, status bar color doesn't change. I tried that at the beginning of my work. Do you know why it might happen? – Orcun Sevsay Apr 01 '15 at 17:56
  • @MiloRambaldi, Hi! Do you fix this issue? – BArtWell Jul 06 '15 at 06:46
  • In my project, when I call `setStatusBarColor(int)` status bar color doesn't change; but if I add flag before setting statusbar color like this: `window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);` status bar color changes. I'm still confused about it. – Orcun Sevsay Jul 06 '15 at 06:59
  • @MiloRambaldi, It is correct for me too. Moreover when I am trying to use Theme.Material.Light in styles, I also get issue with window height. – BArtWell Jul 06 '15 at 07:05
  • 1
    @BArtWell I hope someone fix this issue :) – Orcun Sevsay Jul 06 '15 at 07:26

1 Answers1

3

In my case, problem was occured in SlidingMenu library. Here is a solution.

BArtWell
  • 4,176
  • 10
  • 63
  • 106
  • 1
    Thanks a lot. It also worked on AndroidResideMenu library too. [Here](http://stackoverflow.com/questions/28952210/android-residemenu-library-bottom-of-fragment-has-cropping-issue) is the similar solution I've done. – Orcun Sevsay Jul 07 '15 at 14:24