Android 動態切換全屏和非全屏模式

 代碼示例:

  1. package com.screen;   
  2.    
  3. import android.app.Activity;   
  4. import android.os.Bundle;   
  5. import android.view.View;   
  6. import android.view.WindowManager;   
  7. import android.view.View.OnClickListener;   
  8. import android.widget.Button;   
  9.    
  10. public class MainActivity extends Activity {   
  11.        
  12.     private boolean isFulllScreen = false;   
  13.     private Button button;   
  14.        
  15.     @Override   
  16.     public void onCreate(Bundle savedInstanceState) {   
  17.         super.onCreate(savedInstanceState);   
  18.         setContentView(R.layout.main);   
  19.         button = (Button)findViewById(R.id.button);   
  20.         button.setOnClickListener(new OnClickListener() {   
  21.                
  22.             @Override   
  23.             public void onClick(View v) {   
  24.                 isFulllScreen = !isFulllScreen;   
  25.                 if (isFulllScreen) {   
  26.                     button.setText(getResources().getText(R.string.exit_full_screen));   
  27.                     WindowManager.LayoutParams params = getWindow().getAttributes();   
  28.                     params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;   
  29.                     getWindow().setAttributes(params);   
  30.                     getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);   
  31.                 } else {   
  32.                     button.setText(getResources().getText(R.string.full_screen));   
  33.                     WindowManager.LayoutParams params = getWindow().getAttributes();   
  34.                     params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);   
  35.                     getWindow().setAttributes(params);   
  36.                     getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);   
  37.                 }   
  38.             }   
  39.         });   
  40.            
  41.     }   
  42. }   

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章