Home > Software engineering >  How to change the border color of CardView by first clicking and again change back to previous color
How to change the border color of CardView by first clicking and again change back to previous color

Time:04-23

How to do it using selector instead of changing background?

if(isSelected) {
                binding.cvStainMaster.setBcackgroundResource(R.drawable.boarder_blue_corner);
                binding.btnStart.setBackgroundResource(R.drawable.bg_button_primary);
                isSelected = false;
            }else{
                binding.cvStainMaster.setBackgroundColor(Color.WHITE);
                binding.btnStart.setBackgroundResource(R.drawable.button_background_with_corner);
                isSelected = true;
            }

I have done it by changing background. but I want it to do using selector

CodePudding user response:

Using the androidx.cardview.widget.CardView there is no any property to change the border/stroke colour but you can achieve it using the com.google.android.material.card.MaterialCardView from unselected_state

Result for android:state_checked=true:

selected_state

  • Related