首先,imagebutton的alpha涉及到2种:
1.设置 imagebutton的src属性选择的图片的透明,这个直接调用 imagebutton类的setAlpha就可以了。
2.设置imagebutton的background的透明度,这个用Imagebutton.getBackground().setAlpha(Int alpha)来设置。
这里的setAlpha(Int alpha) 方法的参数从0 -255,0是透明,255是不透明。
目前还有一个问题不太明白,在oncreate()方法中设置元素的透明度是可以的 ,不会有什么问题,但是如果想要动态的去设置元素的alpha属性就会没有效果。只能用AlphaAnimation 来实现:
AlphaAnimation alpha = new AlphaAnimation(0.7F, 0.3F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
button3.startAnimation(alpha);