//获取屏幕分辨率 方法1
<span style="white-space:pre"> </span>DisplayMetrics dm = new DisplayMetrics(); android.view.Display display = getWindowManager().getDefaultDisplay(); display.getMetrics(dm); <span style="white-space:pre"> </span>screen_w = dm.widthPixels; screen_h = dm.heightPixels;
<pre name="code" class="java">//获取屏幕分辨率 方法
<span style="white-space:pre"> </span>WindowManager windowManager = getWindowManager();<span style="white-space:pre"> </span>Display display = windowManager.getDefaultDisplay();<span style="white-space:pre"> </span>screenWidth = display.getWidth();<span style="white-space:pre"> </span>screenHeight = display.getHeight();
// 获取手机状态栏高度 public static int getStatusBarHeight(Context context) { Class<?> c = null; Object obj = null; Field field = null; int x = 0, statusBarHeight = 0; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); x = Integer.parseInt(field.get(obj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize(x); } catch (Exception e1) { e1.printStackTrace(); } return statusBarHeight; } //用的时候直接调用这个方法。
以下粘贴自,http://xqjay19910131-yahoo-cn.iteye.com/blog/1435249
-----------------------------------------------------------------------------------------------------------------------------------------
设置为无标题
Java代码
- requestWindowFeature(Window.FEATURE_NO_TITLE);
设置为全屏模式getWindow().setFlags
Java代码
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
设置为横屏
Java代码
- setRequesteOrientation(ActivityInfo.SCREEN_ORIENTATION_LADSCAPE);
//---------------------------------------------------------------
在开发中我们经常需要把我们的应用设置为全屏,这里我所知道的有俩中方法,一中是在代码中设置,另一种方法是在配置文件里改
一、在代码中设置:
- view plaincopy to clipboardprint?
- package com.android.tutor;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Window;
- import android.view.WindowManager;
- public class OpenGl_Lesson1 extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //去除title
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- //去掉Activity上面的状态栏
- getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
- WindowManager.LayoutParams. FLAG_FULLSCREEN);
- setContentView(R.layout.main);
- }
- }
在这里要强调一点,设置全屏的俩段代码必须在setContentView(R.layout.main) 之前,不然会报错。
二、在配置文件里修改
(关键代码:
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.tutor"
- android:versionCode="1"
- android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".OpenGl_Lesson1"
- android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-sdk android:minSdkVersion="7" />
- </manifest>
禁止转载