底部弹窗dialog

bottomDialog.gif

1. 自定义BottomPayDialog

package com.example.xingchouwang.view.customView;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.xingchouwang.R;
import com.example.xingchouwang.controller.dao.PayClickListener;


/**
 * [底部弹出dialog]
 *
 **/
public class BottomPayDialog extends Dialog implements View.OnClickListener {
    private PayClickListener listener;

    /**
     * @param context
     */
    public BottomPayDialog(Context context) {
        super(context, R.style.MyDialog);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_dialog_pay);
        Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        layoutParams.dimAmount = 0.5f;
        window.setGravity(Gravity.BOTTOM);
        window.setAttributes(layoutParams);
        window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        // 初始化控件
        TextView close = (TextView) findViewById(R.id.tv_supportpay_close);
        LinearLayout weixin = (LinearLayout) findViewById(R.id.ll_supportpay_weixin);
        LinearLayout zhifubao = (LinearLayout) findViewById(R.id.ll_supportpay_zhifubao);
        close.setOnClickListener(this);
        weixin.setOnClickListener(this);
        zhifubao.setOnClickListener(this);

        //最重要的一句话,一定要加上!要不然怎么设置都不行
//        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        dismiss();
        return true;
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ll_supportpay_weixin) {
            if (listener != null) {
                dismiss();
                listener.weixinPayListener(v);
            }
            return;
        }
        if (id == R.id.ll_supportpay_zhifubao) {
            if (listener != null) {
                dismiss();
                listener.aliPayListener(v);
            }
            return;
        }
        if (id == R.id.tv_supportpay_close) {
//            if (listener != null) {
//                listener.onClick(v);
//            }
            dismiss();
            return;
        }
    }


    public void setPayClickListener(PayClickListener listener) {
        this.listener = listener;
    }
}

2. 在代码中使用

/**
     * 显示支付窗口
     */
    private void showDialog() {
        BottomPayDialog bottomPayDialog = new BottomPayDialog(this);
        bottomPayDialog.setPayClickListener(new PayClickListener() {
            @Override
            public void weixinPayListener(View v) {
                KKKKK.showToast(SupportPayaddressActivity.this, "微信支付暂未开通,请使用其它支付方式");
            }

            @Override
            public void aliPayListener(View v) {
                aliPay();
            }
        });
        bottomPayDialog.show();
    }

3. 弹出框布局文件




    

    

        

            

            
        

        

        

            

            
        

    

    

    

    


4. 自定义style

  

你可能感兴趣的:(底部弹窗dialog)