android 自定义Dialog(底部弹窗)

1、自定义


public class ButtomDialogView extends Dialog {
    private boolean iscancelable;//控制点击dialog外部是否dismiss
    private boolean isBackCancelable;//控制返回键是否dismiss
    private boolean isBackCanCelable;//
    private View view;
    private Context context;

    public ButtomDialogView(Context context, View view, boolean isCancelable,boolean isBackCancelable) {
        super(context, R.style.MyDialog);

        this.context = context;
        this.view = view;
        this.iscancelable = isCancelable;
        this.isBackCanCelable=isBackCancelable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

		(这里可以R.layout.view)
        setContentView(view);//这行一定要写在前面
        setCancelable(iscancelable);//点击外部不可dismiss
        setCanceledOnTouchOutside(isBackCanCelable);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;//设置宽高模式,
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;//设置宽高模式,
        window.setAttributes(params);
    }

}

2、R.style.MyDialog,在value文件夹下找到style,将下述代码加进去


   

3、调用



    public void showShareTable(){
        View contentview = LayoutInflater.from(this).inflate(R.layout.popwindow_detail_share, null);

        ButtomDialogView dialogView=new ButtomDialogView(this,contentview,true,true);
        dialogView.show();

    }




java中调整布局对其等参数;

// # 学校
school_page是Button;
RelativeLayout.LayoutParams schoolParams = (RelativeLayout.LayoutParams) school_page.getLayoutParams();
schoolParams.width = (153 * width / 1334) + 60;
schoolParams.height = 226 * height / 750;
schoolParams.leftMargin = 633 * width / 1334;
schoolParams.topMargin = 227 * height / 750;
school_page.setLayoutParams(schoolParams);

你可能感兴趣的:(android 自定义Dialog(底部弹窗))