如何setAlpha到Android按钮 [英] How to setAlpha to android Button

查看:410
本文介绍了如何setAlpha到Android按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个按钮,共享相同的背景图片,我想用阿尔法禁用按钮其中之一。

I have three buttons, sharing same background image, i want to disable button one of them by using Alpha.

但是,当我使用下面的code:

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.

推荐答案

您可以使用 AlphaAnimation 的任何视图设置阿尔法

You can set alpha using AlphaAnimation to any view

样品code

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

这篇关于如何setAlpha到Android按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆