I\'d like to gray out a button so it appears disabled to the user, but still listen for clicks so that I can display a message to the user that explains why the button isn\'
If your button is on the newer types that controls color via backgroundTint
rather then background
, this is what you should do:
if (enabled) {
ViewCompat.setBackgroundTintList(btn, getResources().getColorStateList(R.color.button_states)); // either use a single color, or a state_list color resource
} else {
ViewCompat.setBackgroundTintList(btn, ColorStateList.valueOf(Color.GRAY));
}
// make sure we're always clickable
btn.setEnabled(true);
btn.setClickable(true);