将activity的显示区域扩展至状态栏

先获取状态栏的高度:

statusHeight

方法如下:

	Class c = null;
        Object obj = null;
        java.lang.reflect.Field field = null;
        int x = 0;
        try
        {
            c = Class.forName("com.android.internal.R$dimen");
            obj = c.newInstance();
            field = c.getField("status_bar_height");
            x = Integer.parseInt(field.get(obj).toString());
            statusHeight = IFGAppParams.getAppContext().getResources().getDimensionPixelSize(x);
            return statusHeight;
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return statusHeight;

然后对DecorView 增加statusHeight高度的同时,向上滑动statusHeight即可:

	getWindow().setLayout(LayoutParams.MATCH_PARENT, ScreenUtil.height
                        + statusHeight);
        getWindow().getDecorView().scrollTo(0, statusHeight);


你可能感兴趣的:(android,状态栏,DecorView,android,编程)