如何在 Android 中将活动设置为全屏模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12388771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set activity to fullscreen mode in Android?
提问by Ranjit Chandel
How to set full screen mode for activity in Android? I am using the following code to set full screen but it generates an error:
如何在 Android 中为活动设置全屏模式?我正在使用以下代码设置全屏,但会产生错误:
Exception:
例外:
android.util.AndroidRuntimeException:
requestFeature() must be called before adding content.
Code:
代码:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
回答by Athul Harikumar
please check the code
请检查代码
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);
}
and note it is set before setting the content view
并注意它是在设置内容视图之前设置的
回答by imperator_sp
try this in AndroidManifest:
在 AndroidManifest 中试试这个:
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
回答by Roadies
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
回答by Priyank Patel
put requestWindowFeaturefirst in your code....like this...
将requestWindowFeature放在您的代码中....像这样...
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);