Manish Manish - 1 year ago 168
Android Question

Android: FLAG_TRANSLUCENT_STATUS is not providing correct screen height

In my application, I am displaying list of cards. If first card is visible then status bar translucent and non-translucent for other list items. To achieve this I have used


It is shifting screen and I am not getting correct screen height. I have set list item height as match parent but getHeight is returning height value as screen height - status bar height.

Answer Source

Setting TreeObserver on Window view has worked for me. After adding FLAG_TRANSLUCENT_STATUS, added tree observer and inside it I set the parent view padding which had invoked onLayout method of the parent view and painted layout properly

getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download