RadioButton的样式设置 以及使用

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

RadioButton通常要配合RadioGroup使用 

基础的RadioButton使用的xml代码如下

    
        
        

    

实现的效果 

RadioButton的样式设置 以及使用_第1张图片

去掉 按钮 ,保留文字的效果

在drawable目录下新建一个样式 




    
        
            
            
        
    

    
        
            
            
        
    

Activity 的 xml代码为 : 

    
        
        

    

效果为 

RadioButton的样式设置 以及使用_第2张图片

下面来添加点击监听事件 

在 Java代码中添加 

        RadioGroup radioGroup = findViewById(R.id.act_test_radioGroup);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = group.findViewById(checkedId);
                Toasty.normal(MainActivity.this, radioButton.getText()).show();
            }
        });

 

转载于:https://my.oschina.net/lanyu96/blog/2995356

你可能感兴趣的:(RadioButton的样式设置 以及使用)