http://www.jb51.net/article/104485.htm
一、获得屏幕高度和宽度
1、
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
2、
WindowManager wm = this.getWindowManager();
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
3、
//DisplayMetrics mDisplayMetrics= getResources().getDisplayMetrics();
DisplayMetrics mDisplayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics);
density = mDisplayMetrics.density;
densityDPI = mDisplayMetrics.densityDpi;
xdpi = mDisplayMetrics.xdpi;
ydpi = mDisplayMetrics.ydpi;
int W = mDisplayMetrics.widthPixels;
int H = mDisplayMetrics.heightPixels;
Log.i("Main", "Width = " + W);
Log.i("Main", "Height = " + H);
二.获取状态栏高度:
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
四、 导航栏
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置标题
getSupportActionBar().setTitle("listView");
//设置标题不显示
getSupportActionBar().setDisplayShowTitleEnabled(false);
// 给左上角图标的左边加上一个返回的图标,其id为:android.R.id.home
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//隐藏 actionBar
this.getSupportActionBar().hide();
注: 把 requestWindowFeature(Window.FEATURE_NO_TITLE);放在super.onCreate(savedInstanceState);前面就可以隐藏ActionBar而不报错。
五、隐藏状态栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//隐藏状态栏
View decorView = getWindow().getDecorView();
//第一种
//decorView.setSystemUiVisibility(View.INVISIBLE);//gone无效,invisible有效
//第二种
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
六、去掉所有Activity界面的标题栏
修改AndroidManifest.xml
在application 标签中添加android:theme="@android:style/Theme.NoTitleBar"
**七、去掉所有Activity界面的TitleBar 和StatusBar **
修改AndroidManifest.xml
在application 标签中添加
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
八、屏幕设置
//设置为全屏
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN , WindowManager.LayoutParams.FLAG_FULLSCREEN);
//设置横屏模式
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
或在Activity中添加:
android:screenOrientation="landscape"
//设置竖屏模式
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
或在Activity中添加:
android:screenOrientation="portrait"
网友评论