Android 如何更改标准系统按钮的背景透明度

Android 如何更改标准系统按钮的背景透明度,android,button,view,android-widget,Android,Button,View,Android Widget,我的一项活动中有一组按钮。这些按钮看起来不错,因为它们来自Android系统(灰色),因为我的活动背景是灰色的。我试过以下方法 button.setBackgroundColor(Color.argb(125, 200, 200, 200)); 这创造了所需的透明度,但我失去了按钮状态,如按下,向上等 我如何保持android附带的按钮状态,并且只减少不透明度?在xml中,对于所需的按钮,您应该能够简单地放置: android:background=“@android:color/transp

我的一项活动中有一组按钮。这些按钮看起来不错,因为它们来自Android系统(灰色),因为我的活动背景是灰色的。我试过以下方法

button.setBackgroundColor(Color.argb(125, 200, 200, 200));
这创造了所需的透明度,但我失去了按钮状态,如按下,向上等


我如何保持android附带的按钮状态,并且只减少不透明度?

在xml中,对于所需的按钮,您应该能够简单地放置:

android:background=“@android:color/transparent”

我用它来显示没有默认灰色背景的可绘制图像


-干杯

在课堂上,请使用以下代码:

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);
我希望我能帮忙

再见

动态方式:

getBackground(),如果将位图设置为背景,则通常返回BitmapDrawable;如果将颜色设置为背景,则返回ColorDrawable。
i、 e.
ColorDrawable ColorDrawable=(ColorDrawable)按钮。getBackground()
可着色。setAlpha(125)

这样行得通

静态方式:

在布局中,设置背景色,如#7EC8C8C8

警告这将删除所有背景。。。甚至不会有轮廓,因为整个按钮图像实际上是background@Tanyna博纳尔多:是的,你帮了我的忙,很棒的朋友,正是我想要的,谢谢;)您好,它确实有效,但这是使用动画更改不透明度的最佳方式吗?我认为如果你改变背景可绘制的alpha通道会更好。