package com.screen;
2.
3. import android.app.Activity;
4. import android.os.Bundle;
5. import android.view.View;
6. import android.view.WindowManager;
7. import android.view.View.OnClickListener;
8. import android.widget.Button;
9.
10. public class MainActivity extends Activity {
11.
12. private boolean isFulllScreen = false;
13. private Button button;
14.
15. @Override
16. public void onCreate(Bundle savedInstanceState) {
17. super.onCreate(savedInstanceState);
18. setContentView(R.layout.main);
19. button = (Button)findViewById(R.id.button);
20. button.setOnClickListener(new OnClickListener() {
21.
22. @Override
23. public void onClick(View v) {
24. isFulllScreen = !isFulllScreen;
25. if (isFulllScreen) {
26. button.setText(getResources().getText(R.string.exit_full_screen));
27. WindowManager.LayoutParams params = getWindow().getAttributes();
28. params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
29. getWindow().setAttributes(params);
30. getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
31. } else {
32. button.setText(getResources().getText(R.string.full_screen));
33. WindowManager.LayoutParams params = getWindow().getAttributes();
34. params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
35. getWindow().setAttributes(params);
36. getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
37. }
38. }
39. });
40.
41. }
42.}
Android 动态切换全屏和非全屏模式
最新推荐文章于 2024-05-13 14:57:40 发布