如何将Alpha设置为Android按钮

Him*_*shu 10 android

我有三个按钮,共享相同的背景图像,我想通过使用Alpha禁用其中一个按钮.

但是,当我使用以下代码时:

 button1.getBackground().setAlpha(45);
Run Code Online (Sandbox Code Playgroud)

它正在改变所有三个按钮的背景.但我只需要一个.我们可以通过Alpha()使用吗?或者我们可以使用的其他一些东西,以便按钮看起来处于禁用模式.

Sun*_*hoo 20

您可以将alpha设置AlphaAnimation为任何视图

示例代码

Button btn = (Button) findViewById(R.id.button);  
float alpha = 0.45f;
AlphaAnimation alphaUp = new AlphaAnimation(alpha, alpha);
alphaUp.setFillAfter(true);
btn.startAnimation(alphaUp);
Run Code Online (Sandbox Code Playgroud)


Faa*_*hir 6

nextBtn.getBackground().setAlpha(100);
Run Code Online (Sandbox Code Playgroud)

要么

nextBtn.setAlpha(0.5f); 
Run Code Online (Sandbox Code Playgroud)