问题描述:

I am creating a system-wide fullscreen overlay layout in my activity code(not xml). The problem is that the layout does not occupy the full height of the screen. There is a gap at the top and bottom. Any idea how to make the layout fit the entire screen height?

mFrameLayout = new FrameLayout(this);

mFrameLayout.setBackgroundColor(getResources().getColor(R.color.black));

mFrameLayout.getBackground().setAlpha(50);

WindowManager.LayoutParams params = new WindowManager.LayoutParams(

WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,

WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,

PixelFormat.TRANSLUCENT

);

WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);

windowManager.addView(mFrameLayout, params);

网友答案:

Simply Change 'FLAG_FULLSCREEN' to 'MATCH_PARENT'.

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);

Or to remove the system ui(Status & Nav Bar) from view too:

    int KitKatFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 
        | View.SYSTEM_UI_FLAG_LOW_PROFILE
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

getWindow().getDecorView().setSystemUiVisibility(KitKatFlags);
相关阅读:
Top