读书人

Android学习 之 动态切换全屏跟非全屏

发布时间: 2012-09-28 00:03:35 作者: rapoo

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() {@Overridepublic 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);}}});            }}

?

读书人网 >Android

热点推荐