2

Android タブレット システム バーの高さが必要であるという問題があります。hereと同じ問題ですが、DisplayMetrics と同じサイズになるため、この回答は使用できません。どちらの方法でも、このバーですでに計算されている解像度を取得します。(この問題はスマートフォンでは発生せず、タブレットでのみ発生します)。

4

3 に答える 3

11
// status bar (at the top of the screen on a Nexus device) 
public static int getStatusBarHeight(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}

// navigation bar (at the bottom of the screen on a Nexus device)
public static int getNavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}
于 2013-11-01T00:11:50.407 に答える
0

こちらの回答をご覧ください: https://stackoverflow.com/a/8367739/807499

画面全体の高さになります。次に、DisplayMetrics またはルート レイアウトのサイズで指定されたサイズを差し引くことができます。

于 2012-04-30T20:45:08.463 に答える
0

Chris Banes は、最近の Droidcon トークでこれについて言及しました。全体の話は非常に関連性がありますが、ここにあなたの質問に答える部分へのリンクがあります (タブレットを含むすべてのフォーム ファクター)。

https://youtu.be/_mGDMVRO3iE?t=1093

これは、ステータス バーとナビゲーション バーのサイズを取得する正しい方法です: setOnApplyWindowListener

これが役立つことを願っています!

于 2018-02-06T21:37:04.627 に答える