首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

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

2012-09-28 
Android学习 之 动态切换全屏和非全屏模式直接贴出代码:?package com.screenimport android.app.Activity

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);}}});            }}

?

热点排行