For those who are still looking for a solution to this:
Method setBackgroundDrawable(Drawable d) deprecated as API 16
Assuming your button id buttonId, and your drawable is called button_img, handle this using the following in the onCreate method:
((Button)(findViewById(R.id.buttonId))).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Drawable d = v.getResources().getDrawable(R.drawable.button_img);
d.setAlpha(40);
if (Build.VERSION.SDK_INT >= 16)
v.setBackground(d);
else
v.setBackgroundDrawable(d);
}
});
Tested and works for me!
source
share