radiobutton设置样式

单选题里会用到radiobutton,如果不想使用系统提供的圆圈样式,可以自定义样式,想要做成的效果就是,

使用自定义的图片替换圆圈,然后选择有4个选项的其中一个,图片上有个对勾标记,

然后如果正确选项是帅哥,则选择A后,图片替换成

所以首先在xml属性里,将自定义的图片替换圆圈:关键就是

 android:button="@drawable/c" 这一句:
  <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="丑男"
            android:button="@drawable/c" />

然后在代码中设置监听事件,当选中了正确答案,

rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                 result = (RadioButton)findViewById(checkedId);
                 if (result.getText().toString().equals("帅哥"))
                     {
                     result.setButtonDrawable(R.drawable.b1);//选对后替换打钩的图片
                     
                     resultDetail.setVisibility(View.VISIBLE); 
                     resultDetail.setText("恭喜你,答对了!");
                     
                 }else {
                     resultDetail.setVisibility(View.VISIBLE); 
                     resultDetail.setText("很遗憾,答错了!");
                 }  
              
            }
        });

 

转载于:https://www.cnblogs.com/lucky-star-star/p/3819728.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值