android - 我可以在 android 中自定义多选警报对话框吗?

标签 android android-custom-view android-alertdialog android-dialog

我正在创建一个多选银行列表。当用户选择 多家银行 我想显示所选银行的数量 在右上角,在警报对话框的标题旁边。

我还想自定义复选框和银行名称[列表项] 我可以在警告对话框中这样做吗?我该如何实现?

最佳答案

是的,您为它创建了一个自定义的 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();

关于android - 我可以在 android 中自定义多选警报对话框吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53777298/

相关文章:

android - 更改动态添加的 View 的高度

android - 在屏幕的特定位置绘制自定义 View - Android

java - 应用程序被终止时,AlertDialog 不会出现在屏幕上

java - 在 Eclipse 中生成项目时出错

android - 打开时关闭状态栏 : Android

android - 无法在 android 中启动 cygpath

android - 如何旋转使用 ARCORE SceneView 渲染的 3d 模型

android - RecyclerView 和数据绑定(bind)不起作用

android - 如果未选中复选框,则禁用 AlertDialog PositiveButton

android - 是否有可能 Dialog 可以在 Android 中同时使用圆角和 Day Night 主题的组合?