I have a button:
<Button
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="@string/male"
android:id="@+id/btn_mgen_m"
android:layout_gravity="center_horizontal"
android:background="@drawable/bg_tgl_btn_left"
android:textColor="#444444" />
and I changed its color like this:
btnMgenM = (Button) findViewById(R.id.btn_mgen_m);
btnMgenM.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnMgenM.setBackgroundColor(Color.parseColor("#dca8c3"));
}
});
The background color is changed properly but it seems to remove the background drawable. The round radius, text color and border are removed just the simple colored button is left. I want to change the background color when I click this button, but not change anything else.
How can I do this?
Try this both of line
btnMgenM.setBackgroundResource(0);
btnMgenM.setBackgroundColor(Color.parseColor("#dca8c3"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With