Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS" affects getRootView().getHeight()

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!

like image 473
Orcun Sevsay Avatar asked Mar 31 '15 15:03

Orcun Sevsay


1 Answers

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

like image 135
BArtWell Avatar answered Oct 03 '22 03:10

BArtWell