瑾冰

Android 获取导航栏的高度

电脑版发表于:2020/4/8 9:28

获取Android手机屏幕的高度

/**
 * 获取状态栏高度 
 * 
 * @param context 上下文
 * @return 高度
 */public static int getStatusBarHeight(Context context) {
    int result = 0;
    int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resId > 0) {
        result = context.getResources().getDimensionPixelSize(resId);
    }
    return result;}
/**
 * 获取导航栏高度
 *
 * @param context 上下文
 * @return 高度
 */public static int getNavigationHeight(Context context) {
    int resourceId = 0;
    int rid = context.getResources().getIdentifier("config_showNavigationBar", "bool", "android");
    if (rid != 0) {
        resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        return context.getResources().getDimensionPixelSize(resourceId);
    } else{
        return 0;
    }}


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢