nowindxdw
11/2/2017 - 7:49 AM

动态切换全屏,非全屏

Android学习 之 动态切换全屏和非全屏模式
  直接贴出代码:
package com.screen;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 
 public class MainActivity extends Activity {
 private boolean isFulllScreen = false;
 private Button button;
 
 @Override public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  button = (Button)findViewById(R.id.button);

  button.setOnClickListener(new OnClickListener() {
 @Override public void onClick(View v) {
  isFulllScreen = !isFulllScreen;
  if (isFulllScreen) {
   button.setText(getResources().getText(R.string.exit_full_screen));
   WindowManager.LayoutParams params = getWindow().getAttributes();
   params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
   getWindow().setAttributes(params);
   getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  } else {
  button.setText(getResources().getText(R.string.full_screen));
  WindowManager.LayoutParams params = getWindow().getAttributes();
  params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
  getWindow().setAttributes(params);
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
  }
 }
 });
  }
}