于是,我们就可以算出状态栏的高度了。
Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top;
int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop(); //statusBarHeight是上面所求的状态栏的高度 int titleBarHeight = contentTop - statusBarHeight
方法 1.
WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();
DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm);//this指当前activity screenWidth =dm.widthPixels; screenHeight =dm.heightPixels;
设置为无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequesteOrientation(ActivityInfo.SCREEN_ORIENTATION_LADSCAPE);
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); } }
二、在配置文件里修改
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
如果想只是去除标题栏就后面不用加Fullscreen了,另外,如果想要整个应用都去除标题栏和状态栏,就把这句代码加到<application。。标签里面,如果只是想某个activity起作用,这句代码就加到相应的activity上):
<?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>