您的位置:首页 > 移动开发 > Android开发

android动态全屏切换

2012-08-16 18:52 417 查看
import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.WindowManager;

import android.widget.Button;

public class FullScreenTestActivity extends Activity {

private Button button;

private boolean isFulllScreen;

/** Called when the activity is first created. */

@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("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("full_screen");

WindowManager.LayoutParams params = getWindow().getAttributes();

params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().setAttributes(params);

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

}

}

});

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: