import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
/**
* Created by A007 on 2016/11/3.
* XX有限公司 AndroidTest项目
* 没有白色背景可自定义小大小dialog
* 1.new
* 2.setCustomView
*/
public class CustomDialog extends Dialog {
protected Context context;
public CustomDialog(Context context) {
super(context, R.style.MyCustomDialog);
this.context = context;
}
public CustomDialog(Context context, int themeResId) {
super(context, themeResId);
this.context = context;
}
protected CustomDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
super(context, cancelable, cancelListener);
}
/**
* @param context 上下文对象
* @param layoutId 视图ID
* @param height dialog将要显示的高度
* @param width dialog将要显示的宽度
*/
public CustomDialog setCustomView(Activity context, int layoutId, int height, int width) {
View mView = LayoutInflater.from(getContext()).inflate(layoutId, null);
super.setContentView(mView);
WindowManager.LayoutParams p = this.getWindow().getAttributes(); // 获取对话框当前的参数值
p.height = dip2px(height);
p.width = dip2px(width);
getWindow().setAttributes(p);
show();
return this;
}
/**
* @param context 上下文对象
* @param layoutId 视图ID
* @param scaleHeight dialog将要缩放显示高度的比例
* @param scaleWidth dialog将要缩放显示宽度的比例
*/
public CustomDialog setCustomView(Activity context, int layoutId, float scaleHeight,
CustomDialog(没有白色背景的弹窗)
最新推荐文章于 2024-08-05 17:58:14 发布