一、RaidoButton
1. 效果图
2. activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="14dp"
android:text="@string/tv_desc"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RadioGroup
android:id="@+id/rg_sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="53dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<RadioButton
android:id="@+id/rb_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rb_male"/>
<RadioButton
android:id="@+id/rb_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rb_female"/>
</RadioGroup>
</androidx.constraintlayout.widget.ConstraintLayout>
3. MainActivity.java
public class MainActivity extends AppCompatActivity {
@BindView(R.id.rg_sex)
RadioGroup mSelectSex;
@BindView(R.id.rb_male)
RadioButton mMale;
@BindView(R.id.rb_female)
RadioButton mFemale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
@OnCheckedChanged({
R.id.rb_male,R.id.rb_female})
public void onRadioCheck(CompoundButton view,boolean isChanged) {
switch (view.getId()) {
case R.id.rb_male:
if (isChanged) {
Toast.makeText(this,"you select male",Toast.LENGTH_SHORT).show();
}
break;
case R.id