Android's own bullet frame is ugly and troublesome, it is better to define the bullet frame yourself.
1. Come on a button and give a listener event. Trigger a popup when the button is clicked
Two, come to an AlertDialog.Builder
Three, create an alertDialog
Fourth, use alertdialog's setView to load a view defined by ourselves (the view code will not be recorded)
Five, then submit the view, get our custom control to implement the monitoring method
Six, realize the click method, run to see the effect
7. Repair, click the blank but the pop-up window will not disappear and click the button to close the pop-up window
8. The main code is as follows
//按钮监听事件
public void sss(View view) {
builder = new AlertDialog.Builder(this);
alertDialog = builder.create();
View inflate = View.inflate(this, R.layout.dialog, null);
alertDialog.setView(inflate);
// 點擊空白不關閉彈窗
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
inflate.findViewById(R.id.btn_yes).setOnClickListener(this);
inflate.findViewById(R.id.btn_no).setOnClickListener(this);
}
@SuppressLint("NonConstantResourceId")
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_yes:
Toast.makeText(this,"yes",Toast.LENGTH_SHORT).show();
// 關閉彈窗
alertDialog.dismiss();
break;
case R.id.btn_no:
Toast.makeText(this,"no",Toast.LENGTH_SHORT).show();
alertDialog.dismiss();
break;
}
}