首先您需要绑定您的按钮在活动这样
btnMale=(Button) findViewById(R.id.btnMale);
btnFemale=(Button) findViewById(R.id.btnFemale);
比我们的按钮setOnClickListener()这样
btnMale.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//btnMale.setBackgroundResource(R.drawable.background);// change background your button like this
btnMale.setBackgroundColor(ContextCompat.getColor(MainActivity.this,R.color.colorPrimary));// use this to set color as background
btnFemale.setBackgroundResource(android.R.drawable.btn_default;);// use this to set color as background
}
});
btnFemale.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnFemale.setBackgroundColor(ContextCompat.getColor(MainActivity.this,R.color.colorPrimary));// use this to set color as background
btnMale.setBackgroundResource(android.R.drawable.btn_default;);// use this to set color as background
}
});