安卓全屏活动错误

3

我正在尝试创建一个全屏活动:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);
   }

I get the following error:

requestFeature() must be called before adding content

你正在使用ActionBarSherlock还是AppCompat? - Pedro Lobito
1个回答

3

在执行super.onCreate之前,使用requestWindowFeature函数

public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
   }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接