我可以在 android 中自定义多选警报对话框吗?
Can I customize multichoice Alert Dialog in android?
我正在创建一个 multi-choice 银行列表。当用户选择
多家银行 我想显示所选银行的数量
在右上角,在警报对话框的标题旁边。
我还想自定义复选框和银行名称[列表项]
我可以在警告对话框中这样做吗?我该如何实现?
是的,您为其创建了一个自定义 AlertDialog。首先为它做一个布局。然后像这样用它来自定义AlertDialog-
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
View view = layoutInflater.inflate(R.layout.popup_layout,null);
final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.setView(view);
//You can find your view like this
TextView txtMsg = (TextView) view.findViewById(R.id.txtMsg);
txtMsg.setText("");
//Or if u want to provide any button
view.findViewById(R.id.btnOK).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
// your function
}
});
alertDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //if u want to give any animation
alertDialog.show();
我正在创建一个 multi-choice 银行列表。当用户选择 多家银行 我想显示所选银行的数量 在右上角,在警报对话框的标题旁边。
我还想自定义复选框和银行名称[列表项] 我可以在警告对话框中这样做吗?我该如何实现?
是的,您为其创建了一个自定义 AlertDialog。首先为它做一个布局。然后像这样用它来自定义AlertDialog-
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
View view = layoutInflater.inflate(R.layout.popup_layout,null);
final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.setView(view);
//You can find your view like this
TextView txtMsg = (TextView) view.findViewById(R.id.txtMsg);
txtMsg.setText("");
//Or if u want to provide any button
view.findViewById(R.id.btnOK).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
// your function
}
});
alertDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //if u want to give any animation
alertDialog.show();