`
crazier9527
  • 浏览: 994859 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android 动态切换全屏和非全屏模式

阅读更多

直接贴出代码:

 

Java代码  收藏代码
  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. }  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics