我正在像这样在AlertDialog中建立一个RadioGroup:
val items = listOf("1", "2")
AlertDialog.Builder(activity, R.style.MyStyle)
.setSingleChoiceItems(items.toTypedArray(), 0) { dialog, index ->
dialog.dismiss().
}
.show()
我期望的结果是使AlertDialog看起来像这样:
因此,使用样式,我需要删除实际的RadioButton可绘制对象,然后使当前选择的RadioButton具有灰色背景。
如何使用Android样式实现此设计?
此数据显示在列表中?还是它的硬编码数据?
如果是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,它是适用的