获取Android状态栏高度

来源:互联网 发布:eclipse的java程序编码 编辑:程序博客网 时间:2024/06/03 19:15
public int getStatusBarHeight(Context context){    int statusBarHeight = 0;    try {        Class<?> clazz = Class.forName("com.android.internal.R$dimen");        Object obj = clazz.newInstance();        String heightStr = clazz.getField("status_bar_height").get(obj).toString();        //获取状态栏高度的id        int heightId = Integer.parseInt(heightStr);        statusBarHeight =  context.getResources().getDimensionPixelSize(heightId);    } catch (Exception e) {        e.printStackTrace();    }    return statusBarHeight;}