2014-01-25 42 views
2

我在使用命中START按鈕時將全屏設置爲特定活動。android-requestWindowFeature(Window.FEATURE_NO_TITLE)例外

在這種情況下,調用showStopButton()

它運行良好。但如果我插入

requestWindowFeature(Window.FEATURE_NO_TITLE); 

然後它崩潰,說明它應該在添加內容之前調用。

我應該如何處理它以設置NO_TITLEFULL_SCREEN

private void showStopButton(){ 

    // requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 
    getWindow().findViewById(android.R.id.content).requestLayout(); 

    // handle element visibility 
((Button)findViewById(R.id.stopButton)).setEnabled(false); 
    ((Button)findViewById(R.id.startButton)).setVisibility(View.GONE); 
    ((Button)findViewById(R.id.stopButton)).setVisibility(View.VISIBLE); 
    ((SeekBar)findViewById(R.id.seekBar1)).setVisibility(View.VISIBLE); 
    ((Button)findViewById(R.id.resetButton)).setVisibility(View.GONE); 
    ((Button)findViewById(R.id.saveButton)).setVisibility(View.GONE); 
} 

我當啓動按鈕重新顯示相反的過程,它的跑細 在這種情況下,我刪除了全屏模式

 private void showStartButton(){ 

     getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 
     getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     getWindow().findViewById(android.R.id.content).requestLayout(); 
     .... 
    } 
+4

你之前所說的 「requestWindowFeature」 的「的setContentView()」。 –

回答

3

所以:

@Override 
protected void onCreate(
    final Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 

    // Make this activity, full screen 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
     WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    // Hide the Title bar of this activity screen 
    getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

    setContentView(R.layout.main); 

    // MORE INIT STUFF HERE... 
    //img = (ImageView) findViewById(R.id.imgRandom); 
    //btnRandom = (Button) findViewById(R.id.btnRandom); 
} 
+1

是的,這是工作,在onCreate()方法...但我試圖隱藏它在showStop()方法...我睡覺了一會兒後發現解決方案... – erwin

2

它這麼簡單...我只需要隱藏ActionBar ...然後在回到標準屏幕時顯示它...

private void showStopButton(){ 
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 
     ActionBar actionBar = getActionBar(); 
     actionBar.hide(); 
     getWindow().findViewById(android.R.id.content).requestLayout(); 
2

使用-public類MainActivity擴展活動 - 而不是-public類MainActivity擴展ActionBarActivity-

0

試試這個......

public class MainActivity extends Activity { 

    Context context; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     context = this; 

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

     setContentView(R.layout.activity_main); 
    } 
}