Android取得ステータスバー高さエラー一致
1052 ワード
一、はじめにAndroid 7.0以上に全面的なスクリーンフィットを追加したことでステータスバーの高さが一致せず、同じ方法で高低バージョンで一致しない2、方法1:
このメソッドが取得した高さは48 pxメソッド2です.
このメソッドで取得した高さは60 pxです.
/**
*
* @return
*/
public static int getStatueBarHeight2() {
int result = 0;
int resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen",
"android");
if (resourceId > 0) {
result = Resources.getSystem().getDimensionPixelSize(resourceId);
}
return result;
}
このメソッドが取得した高さは48 pxメソッド2です.
/**
*
*
* @param context
* @return
*/
public static int getStatueBarHeight(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;
}
このメソッドで取得した高さは60 pxです.