Manish Manish - 3 days ago 5
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

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);


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

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() {

            }
});
Comments