直接贴出代码:
?
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); } } }); }}
?