当我尝试在MainActivity.java中全屏显示我的应用时,我的应用程序崩溃了。这就是我的全屏代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}
答案 0 :(得分:0)
您正在调用setContentView两次
//setContentView(R.layout.activity_main); //don't call here
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
答案 1 :(得分:0)
请在super.onCreate
上方拨打这些电话,不要拨打setcontentview two删除上方..
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
请参阅文档......
的文档必须在setContentView()之前调用它。
答案 2 :(得分:0)
使用此
机器人:主题=" @android:风格/ Theme.NoTitleBar.Fullscreen"
答案 3 :(得分:0)
You can to this by two way either from AndroidManifest.xml or Activity itself:
1) To set your App or any individual activity display in Full Screen mode, insert the code:
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
2) To set your activity as full screen mode write code before onCreate method,You can do it programatically:
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}