popwindow完全遮盖顶部状态栏

private PopupWindowpopWindow;

private ViewpopView;

private void openPopWindow() {

View parent = getWindow().getDecorView().getRootView();

popView = View.inflate(CheckStandActivity.this, R.layout.pop_01,null);

int width = CheckStandActivity.this.getResources().getDisplayMetrics().widthPixels;

int height = CheckStandActivity.this.getResources().getDisplayMetrics().heightPixels;

Rect frame =new Rect();

getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);

final PopupWindow popWindow =new PopupWindow(popView,width,height+frame.top*2);

//        popWindow = new PopupWindow(popView, width, height);

        popWindow.setAnimationStyle(R.style.pop_bottom_anim_style);

popWindow.setFocusable(true);

popWindow.setOutsideTouchable(false);// 设置同意在外点击消失

        View.OnClickListener listener =new View.OnClickListener() {

public void onClick(View v) {

switch (v.getId()) {

case R.id.btn_ticket://查看票据

                      finish();

break;

case R.id.btn_evaluate://评价

                      finish();

break;

}

}

};

popView.findViewById(R.id.btn_evaluate).setOnClickListener(listener);

popView.findViewById(R.id.btn_ticket).setOnClickListener(listener);

ColorDrawable dw =new ColorDrawable(0xe6F2F2F2);

popWindow.setBackgroundDrawable(dw);

popWindow.setClippingEnabled(false);//fullscreen

        popWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL,0,0);

}

//获取底部快捷键的高度

if (hasNavBar(this)) {

Resources res =this.getResources();

int resourceId = res.getIdentifier("navigation_bar_height","dimen","android");

if (resourceId >0) {

navbarHeight = res.getDimensionPixelSize(resourceId);

}

}

//判断是否有底部快捷键

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)

public static boolean hasNavBar(Context context) {

Resources res = context.getResources();

int resourceId = res.getIdentifier("config_showNavigationBar","bool","android");

if (resourceId !=0) {

boolean hasNav = res.getBoolean(resourceId);

// check override flag

        String sNavBarOverride =getNavBarOverride();

if ("1".equals(sNavBarOverride)) {

hasNav =false;

}else if ("0".equals(sNavBarOverride)) {

hasNav =true;

}

return hasNav;

}else {// fallback

        return !ViewConfiguration.get(context).hasPermanentMenuKey();

}

}

//检查虚拟按键是否被重写

private static String getNavBarOverride() {

String sNavBarOverride =null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

try {

Class c = Class.forName("android.os.SystemProperties");

Method m = c.getDeclaredMethod("get", String.class);

m.setAccessible(true);

sNavBarOverride = (String) m.invoke(null,"qemu.hw.mainkeys");

}catch (Throwable e) {

}

}

return sNavBarOverride;

}

你可能感兴趣的:(popwindow完全遮盖顶部状态栏)