zoukankan      html  css  js  c++  java
  • android 屏幕宽高

    引用:http://dev.10086.cn/cmdn/wiki/index.php?edition-view-5334-1.html

    Android程序中要设置全屏包括两个部分: 窗口 全屏和A ctivity 全屏。

      窗口全屏 是指隐藏系统顶部用来显示时间、电量、信号等信息的 标题栏 ,A ctivity全屏 是指隐藏程序的标题栏。我们可以在程序代码中设置,也可以通过修改AndroidManifest.xml文件来实现。

      1. 修改程序代码 。

      我们需要在 A ctivity的onCreate方法中添加相应的代码。请 注意 代码的位置,要在setContentView()方法之前调用哦。

      Java代码

      1. public class Home extends Activity {

      2.

      3. @Override

      4. protected void onCreate(Bundle savedInstanceState) {

      5. super.onCreate(savedInstanceState);

      6. requestWindowFeature(Window.FEATURE_NO_TITLE);//不显示程序的标题栏

      7. getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,WindowManager.LayoutParams. FLAG_FULLSCREEN);//不显示系统的标题栏

      8. setContentView(R.layout.main);

      9. }

      10.

      11. }

      public class Home extends Activity {

      @Override

      protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      requestWindowFeature(Window.FEATURE_NO_TITLE);//不显示程序的标题栏

      getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,WindowManager.LayoutParams. FLAG_FULLSCREEN);//不显示系统的标题栏

      setContentView(R.layout.main);

      }

      }

      2. 修改 AndroidManifest.xml 。

      我们可以修改< application>标签或< activity>标签的属性值来实现。他们的区别是修改< application>标签后所有的Activity都会全屏,而修改< activity>后只针对当前的 Activity有效。注意:android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 的位置,我在两处都设置上了,大家可以根据实际状况做出调整。

      Xml代码

      1. < ?xml version="1.0" encoding="utf-8"?>

      2. < manifest xmlns:android="http://schemas.android.com/apk/res/android"3. package="org.dw.enotes"

      4. android:versionCode="1"

      5. android:versionName="1.0">

      6. < application android:icon="@drawable/icon"

      7. android:label="@string/app_name"

      8. < !-- 看这里 -->

      9. android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

      10.

      11. < activity

      12. android:name=".activity.Hello"

      13. android:label="@string/app_name"

      14. < !-- 看这里 -->

      15. android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

      16. < intent-filter>

      17. < action android:name="android.intent.action.MAIN" />

      18. < category android:name="android.intent.category.LAUNCHER" />

      19. < /intent-filter>

      20. < /activity>

      21. < /application>

      22. < uses-sdk android:minSdkVersion="4" />

      23. < /manifest>

      < ?xml version="1.0" encoding="utf-8"?>

      < manifest xmlns:android="http://schemas.android.com/apk/res/android"

      package="org.dw.enotes"

      android:versionCode="1"

      android:versionName="1.0">

      < application android:icon="@drawable/icon"

      android:label="@string/app_name"

      < !-- 看这里 -->

      android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

      < activity

      android:name=".activity.Hello"

      android:label="@string/app_name"

      < !-- 看这里 -->

      android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

      < intent-filter>

      < action android:name="android.intent.action.MAIN" />

      < category android:name="android.intent.category.LAUNCHER" />

      < /intent-filter>

      < /activity>

      < /application>< uses-sdk android:minSdkVersion="4" />

      < /manifest>

      Android获得屏幕的宽度和高度很简单,只需在Activity中调用以下代码:

      Java代码

      1. int screenWidth;//屏幕宽度

      2. int screenHeight;//屏幕高度

      3. WindowManager windowManager = getWindowManager();

      4. Display display = windowManager.getDefaultDisplay();

      5.

      6. screenWidth = display.getWidth();

      7. screenHeight = display.getHeight();

  • 相关阅读:
    Kmeans中文聚类
    第四周周总结
    数据清洗第一天
    第三周周总结
    关于sqoop上传mysql数据到hive报错的问题
    天津东软实训第十一天——Hive连接JDBC
    天津东软实训第十天——Hive配置
    天津东软实训第九天——MapReduce实战
    天津东软实训第八天------倒排索引
    Intellij IDEA 创建maven项目,利用API操作HDFS
  • 原文地址:https://www.cnblogs.com/sode/p/2408861.html
Copyright © 2011-2022 走看看