Android:AlertDialog中RadioButton的自定义样式

问题描述 投票:0回答:1

我正在像这样在AlertDialog中建立一个RadioGroup:

val items = listOf("1", "2")

AlertDialog.Builder(activity, R.style.MyStyle)
        .setSingleChoiceItems(items.toTypedArray(), 0) { dialog, index ->
            dialog.dismiss().   
        }
        .show()

我期望的结果是使AlertDialog看起来像这样:

enter image description here

因此,使用样式,我需要删除实际的RadioButton可绘制对象,然后使当前选择的RadioButton具有灰色背景。

如何使用Android样式实现此设计?

android radio-button android-alertdialog android-styles
1个回答
0
投票

此数据显示在列表中?还是它的硬编码数据?

如果是listview或recyclerview,则非常容易实现您想要的。在您的适配器中,您只需执行此操作

 holder.cardlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                check=true; // this is local Boolean  type variable
                previousposition = position;  // previouspostion is local int type var 

                notifyDataSetChanged();
            }
        });
        if (check) {
            if (previousposition == position) {

               //set color of card gray here

            } else {
               //set color of card is white here

            }
        }

请记住,如果您使用listview / recyclerview,它是适用的

© www.soinside.com 2019 - 2024. All rights reserved.