2016-08-10 3 views
1

Wenn ich versuche, meine App Vollbild innerhalb MainActivity.java zu machen, wird meine Anwendung abgestürzt. Dies ist, was mein Vollbild-Code ist:Goull Fullscreen durch MainActivity stürzt die App

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

hinzufügen Fehlercode bitte. Ohne es ist deine Frage unklar. –

+0

Entfernen Sie die erste setContentView() und versuchen Sie, log ... –

+1

Ich denke, requestWindowFeature muss vor setContentView aufgerufen werden –

Antwort

0

Sie rufen setContentView zweimal

//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); 
+0

Danke, habe nicht bemerkt, dass ich es zweimal drin hatte. – moxide

0

Bitte rufen Sie diese auf Oberhalb von super.onCreate und rufen Sie nicht setcontentview zwei oben entfernen ..

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); 
} 

Bitte beachten Sie die doc ...

Die Dokumentation für Window.requestFeature():

Dies muss vor setContentView() aufgerufen werden.

0

verwenden

android: theme = "@ android: style/Theme.NoTitleBar.Fullscreen"

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); 
    } 
}