import android.app.Activity;
04.import android.os.Bundle;
05.import android.util.DisplayMetrics;
06.import android.view.Window;
07.import android.view.WindowManager;
08.import android.widget.TextView;
09.
10.public class MainActivity extends Activity {
11.
12. private TextView mTextView;
13.
14. @Override
15. public void onCreate(Bundle savedInstanceState) {
16. super.onCreate(savedInstanceState);
17. //设置为无标题
18. requestWindowFeature(Window.FEATURE_NO_TITLE);
19. //设置为全屏模式
20. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
21. WindowManager.LayoutParams.FLAG_FULLSCREEN);
22. setContentView(R.layout.main);
23. //定义DisplayMetrics对象
24. DisplayMetrics dm = new DisplayMetrics();
25. //获取窗口属性
26. getWindowManager().getDefaultDisplay().getMetrics(dm);
27. //窗口宽度
28. int screenWidth = dm.widthPixels;
29. //窗口高度
30. int screenHeight = dm.heightPixels;
31.
32. mTextView = (TextView)findViewById(R.id.text_view);
33. mTextView.setText("屏幕宽度: "+screenWidth+
34. "\n屏幕高度: "+screenHeight);
35. }
36.}
android代码大全之(二):获取屏幕大小
最新推荐文章于 2022-07-14 14:12:07 发布