1、自定义PopupWindow,只要是重写showAsDropDown()方法
public class PopMyWindow extends PopupWindow {
public PopMyWindow (View contentView, int matchParent, int matchParent1) {
super(contentView, matchParent, matchParent1);
}
@Override
public void showAsDropDown(View anchor) {
if (Build.VERSION.SDK_INT >23) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
}
2、在activity中实现
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.pop, null);
PopMyWindow win = new PopMyWindow (view,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
win .setBackgroundDrawable(new BitmapDrawable());
win .setOutsideTouchable(true);
mPopupWindow.showAsDropDown(mSFTv);//mSFTv:代表要显示在控件mSFTv的下面
//说明一下:如果你在创建PopupWindow的时候,高度设置的是 WRAP_CONTENT,而不是MATCH_PARENT的时候,并且view 里面的内容不会填充整个屏幕或者超过屏幕的时候,则不需要重写PopupWindow 实现 @Override showAsDropDown()方法。