在下面替换您的TestDialogActivity
喜欢,
public class TestDialogActivity extends Activity {
private static final String HALLOWEEN_ORANGE = "#FF7F27";
private AlertDialog alertDialog;
private OnClickListener mShowDialogClickListener = new OnClickListener() {
public void onClick(View v) {
QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(
v.getContext())
.setTitle("Set IP Address")
.setTitleColor(HALLOWEEN_ORANGE)
.setDividerColor(HALLOWEEN_ORANGE)
.setMessage("You are now entering the 10th dimension.")
.setCustomView(R.layout.example_ip_address_layout,
v.getContext())
.setIcon(getResources().getDrawable(R.drawable.ic_launcher));
alertDialog=qustomDialogBuilder.create();
qustomDialogBuilder.setAlertDialog(alertDialog);
alertDialog.show();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt = (Button) findViewById(R.id.button1);
bt.setOnClickListener(mShowDialogClickListener);
}
并替换setCustomView
如下QustomDialogBuilder
public QustomDialogBuilder setCustomView(int resId, final Context context) {
View customView = View.inflate(context, resId, null);
((TextView)customView.findViewById(R.id.ip_text)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
((FrameLayout)mDialogView.findViewById(R.id.customPanel)).addView(customView);
return this;
}
最后将以下行添加到您的QustomDialogBuilder
private AlertDialog alertDialog;
public void setAlertDialog(AlertDialog alertDialog)
{
this.alertDialog=alertDialog;
}
要关闭对话框,请单击IP Address
文本。