0

我有这段代码可以将视图设置为全屏。我想做的是在方向更改为横向时将视图设置为全屏。我已经尝试了许多不同的解决方案,但无法正常工作,任何帮助将不胜感激。

public class FullScreen extends Activity {
@Override
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.main);
}

}

4

1 回答 1

1

这是 yarian 建议的代码:

public class FullScreen extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
    }
}

这可能是最好的解决方案。

于 2013-04-02T22:00:28.577 回答