How To Make An Option Fade But Still Be Clickable On Android Studio?
I currently have a two checkboxes, where when one is clicked, the other automatically unchecks. I would like to keep that however have the unchecked one become a faded white color,
Solution 1:
chk2.setAlpha(0.5f)
would make it appear faded.
chk1.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {
@OverridepublicvoidonCheckedChanged(CompoundButton compoundButton, boolean b) {
chk2.setChecked(false);
chk1.setChecked(b);
chk2.setAlpha(0.5f);
chk1.setAlpha(1f);
}
});
chk2.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {
@OverridepublicvoidonCheckedChanged(CompoundButton compoundButton, boolean b) {
chk1.setChecked(false);
chk2.setChecked(b);
chk1.setAlpha(0.5f);
chk2.setAlpha(1f);
}
});
Solution 2:
You can use different icons for checkboxes when they are in selected and unselected state. Also change the color of the text to make it look faded.
To help with changing checkbox icons, this is helpful
Change icons of checked and unchecked for Checkbox for Android
You can use to change the checkbox icon and text color, chk2.setTextColor(getResources().getColor(R.color.gray)); chk2.setButtonDrawable(R.drawable.unchecked);
Post a Comment for "How To Make An Option Fade But Still Be Clickable On Android Studio?"