问题
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
回答1:
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);
回答2:
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:
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 ? ...
回答4:
Try this:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
回答5:
@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);
...
}
来源:https://stackoverflow.com/questions/9023023/set-full-screen-out-oncreate