我的一个活动中有一组按钮。按钮看起来很好,因为它们来自Android系统(灰色),因为我的activity的背景是灰色的。我尝试过以下几种方法
button.setBackgroundColor(Color.argb(125, 200, 200, 200));它创建了所需的透明度,但我丢失了按钮的状态,如按下、向上等。
我如何才能保持android附带的按钮状态,并且只减少不透明度?
发布于 2012-11-29 22:22:23
在你的类中,使用下面的代码:
alpha = new AlphaAnimation(0.3F, 0.3F); //Set opacity - Range 0.0 to 1.0
alpha.setDuration(0); // Set animation duration
alpha.setFillAfter(true); // Maintaining the effect to the button
yourButton.startAnimation(alpha);我希望我能帮上忙。
再见!
发布于 2012-11-29 22:12:59
在所需按钮的xml中,您应该能够简单地放入:
android:background="@android:color/transparent“
我用它来显示没有默认灰色背景的可绘制。
-cheers
发布于 2012-11-29 22:23:04
动态方式:
Button.getBackground(),如果将位图设置为背景,则通常返回BitmapDrawable;如果将颜色设置为背景,则返回ColorDrawable。
即
ColorDrawable colorDrawable = (ColorDrawable) button.getBackground();
colorDrawable.setAlpha(125);
这将工作得很好。
静态方式:
在布局中,设置背景颜色,如#7EC8C8C8
https://stackoverflow.com/questions/13627518
复制相似问题