I have three buttons, sharing same background image, i want to disable button one of them by using Alpha.
But when i am using the following code:
button1.getBackground().setAlpha(45);
it is changing the background for all three buttons. but i need for only one. can we done by using by Alpha()?? or some other things we can use so that button will looks in disabled mode.
nextBtn.getBackground().setAlpha(100);
or
nextBtn.setAlpha(0.5f);
In my case I set one button to alpha 75. But all the other buttons with same background color also changed to alpha 75. Calling mutate()
solved the problem.
Pavel Dudka' answer works perfectly for my case.
buttonArrivals.getBackground().mutate().setAlpha(180);
buttonDepartures.getBackground().mutate().setAlpha(255);
You can set alpha using AlphaAnimation
to any view
Sample Code
Button btn = (Button) findViewById(R.id.button);
float alpha = 0.45f;
AlphaAnimation alphaUp = new AlphaAnimation(alpha, alpha);
alphaUp.setFillAfter(true);
btn.startAnimation(alphaUp);
Button btn;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.main_btn);
Drawable d = getResources().getDrawable(R.drawable.imagen);
d.setAlpha(60);
btn.setBackgroundDrawable(d);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With