/**
* Created by twy on 2017/7/7.
*/
public class MyPopWindow extends PopupWindow {
public MyPopWindow(final Activity context,View view){
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int h = context.getWindowManager().getDefaultDisplay().getHeight();
int w = context.getWindowManager().getDefaultDisplay().getWidth();
this.setContentView(view);
this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
this.setFocusable(true);
this.setOutsideTouchable(true);
this.update();
ColorDrawable dw = new ColorDrawable(-00000);
this.setBackgroundDrawable(dw);
this.setAnimationStyle(R.style.AnimationPreview);
}
@Override
public void showAsDropDown(View anchor) {
if (Build.VERSION.SDK_INT == 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
}
在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法
最新推荐文章于 2020-11-25 17:11:30 发布