The app I\'m currently working on uses a lot of ImageViews as buttons. The graphics on these buttons use the alpha channel to fade out the edges of the button and make them look
You can combine StateListDrawable
and LayerDrawable
for this.
public Drawable getDimmedDrawable(Drawable drawable) {
Resources resources = getContext().getResources();
StateListDrawable stateListDrawable = new StateListDrawable();
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{
drawable,
new ColorDrawable(resources.getColor(R.color.translucent_black))
});
stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, layerDrawable);
stateListDrawable.addState(new int[]{android.R.attr.state_focused}, layerDrawable);
stateListDrawable.addState(new int[]{android.R.attr.state_selected}, layerDrawable);
stateListDrawable.addState(new int[]{}, drawable);
return stateListDrawable;
}
I assume our colors.xml looks like this
#80000000