popupwindow基本使用

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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章