android从底部弹出弹窗

<img src="https://img-blog.youkuaiyun.com/20160504164048549?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
public class DialogUtil extends Dialog implements
		android.view.View.OnClickListener {
	/**
	 * @author MrQ
	 */
	private TextView titleTv;
	private DialogCallback dialogCallback;
	
	public DialogUtil(Context context,int layoutId,int [] findViewById) {
		super(context, R.style.customDialog);
		initView(context,layoutId,findViewById);
	}
	public void initView(Context context,int layoutId,int [] findViewById) {
		View view = LayoutInflater.from(context).inflate(
				layoutId, null);
		Window window = getWindow();
		window.setGravity(Gravity.BOTTOM);
		window.getDecorView().setPadding(0, 0, 0, 0);
		window.setWindowAnimations(R.style.dialogAnim);
		
		WindowManager windowManager = ((Activity) context).getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		WindowManager.LayoutParams lp = getWindow()
				.getAttributes();
		lp.width = (int) (display.getWidth()); // 设置宽度
		getWindow().setAttributes(lp);
		setContentView(view);
		titleTv = (TextView) view.findViewById(R.id.title_tv);
		for(int i=0;i<findViewById.length;i++){
			view.findViewById(findViewById[i]).setOnClickListener(this);
		}

	}

	public void showDialog(DialogCallback callback) {
		this.dialogCallback = callback;
		show();
	}
	public void showDialog(DialogCallback callback,long l) {
		this.dialogCallback = callback;
		show();
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				dismiss();
			}
		}, l);
	}
	public void setTitle(String title){
		titleTv.setText(title);
	}
	@Override
	public void onClick(View v) {
		if (dialogCallback != null) {
			dialogCallback.onClickBack(v.getId());
		}
	}

	public interface DialogCallback {
		void onClickBack(int id);
	}
}

用的时候

int[] findViewById = new int[] { R.id.del_view,R.id.cancel_view };
final DialogUtil delDialog = new DialogUtil(OwnPlaceEditActivity.this,R.layout.perpage_delprodialog, findViewById);
delDialog.setTitle(getString(R.string.sDelete));
delDialog.showDialog(new DialogCallback() {}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值