0

我想用切換按鈕控制手機的全屏。我做到了,但它只能使用一次。我該如何解決它? 有代碼:全屏切換

final ToggleButton toggle_button_for_full_screen = (ToggleButton) findViewById(R.id.toggleButton1); 
toggle_button_for_full_screen.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
boolean variable_for_saving_toggle_button_status; 

    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
     // TODO Auto-generated method stub 
     if (isChecked) 
      { 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN); 
      } 
     else 
      { 
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 
      } 
    } 
}); 

回答

1

嘗試下面的代碼來做到這一點:

if (isChecked) 
      { 
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
       getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 
      } 
     else 
      { 
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); 
       getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
      } 

它做工精細和我在一起。

+0

是的,它也適用於我,謝謝。 –

+0

請嘗試您支持的所有版本。 –