// 获取屏幕的宽度
public static int getScreenWidth(Context context) {
WindowManager manager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
return display.getWidth();
}
// 获取屏幕的高度
public static int getScreenHeight(Context context) {
WindowManager manager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
return display.getHeight();
}
//得到状态栏的高度
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier(
"status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
// 获取ActionBar的高度
public static int getActionBarHeight(Context contxt) {
TypedValue tv = new TypedValue();
int actionBarHeight = 0;
if (contxt.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))// 如果资源是存在的、有效的
{
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, contxt.getResources().getDisplayMetrics());
}
return actionBarHeight;
}
获取屏幕宽高
最新推荐文章于 2024-09-09 21:32:05 发布