1.popupWindow
public class DemoPopupWindow extends PopupWindow { protected Context mContext; public DemoPopupWindow(Context context) { super(context); mContext = context; LayoutInflater layoutInflater = LayoutInflater.from(context); View contentView = layoutInflater.inflate(R.layout.popup_lay, null); setContentView(contentView); DisplayMetrics dm = context.getResources().getDisplayMetrics(); setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); setBackgroundDrawable(getBackgroundDrawable()); setOutsideTouchable(true); } protected ColorDrawable getBackgroundDrawable() { return new ColorDrawable(Color.TRANSPARENT); } }
2.activity
DemoPopupWindow popupWindow = new DemoPopupWindow(RxJavaActivity.this); popupWindow.showAtLocation(mRootView, Gravity.CENTER, 0, 0);