Set Full Screen out onCreate

2020-04-03 05:25发布

I can only set my Activity to Full Screen in onCreate method (before setContentView)?

Is there any way I can set to full screen outside of onCreate?

Thanks

5条回答
smile是对你的礼貌
2楼-- · 2020-04-03 06:00

The docs for Window.requestFeature says:

This must be called before setContentView().

so no, I don't believe there is another way to set to full screen after you call setContentView.

查看更多
男人必须洒脱
3楼-- · 2020-04-03 06:02

Is possible! Adding this code.


    // go full screen
    WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    mActivity.getWindow().setAttributes(attrs);

    // go non-full screen
    WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
    attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mActivity.getWindow().setAttributes(attrs);

查看更多
小情绪 Triste *
4楼-- · 2020-04-03 06:02
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);   

Use this before setting layout .Because you are trying to set your layout into fullscreen. Why you need outside of on create method ? ...

查看更多
Explosion°爆炸
5楼-- · 2020-04-03 06:21

Try this:

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
查看更多
等我变得足够好
6楼-- · 2020-04-03 06:24
@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

     **requestWindowFeature(Window.FEATURE_NO_TITLE);
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);**

     setContentView(R.layout.activity);

...
}
查看更多
登录 后发表回答