首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改标准系统按钮的背景透明度

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

Stack Overflow用户
提问于 2012-11-29 22:05:53
回答 3查看 952关注 0票数 1

我的一个活动中有一组按钮。按钮看起来很好,因为它们来自Android系统(灰色),因为我的activity的背景是灰色的。我尝试过以下几种方法

代码语言:javascript
复制
button.setBackgroundColor(Color.argb(125, 200, 200, 200));

它创建了所需的透明度,但我丢失了按钮的状态,如按下、向上等。

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-29 22:22:23

在你的类中,使用下面的代码:

代码语言:javascript
复制
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);

我希望我能帮上忙。

再见!

票数 2
EN

Stack Overflow用户

发布于 2012-11-29 22:12:59

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

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

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

-cheers

票数 0
EN

Stack Overflow用户

发布于 2012-11-29 22:23:04

动态方式:

Button.getBackground(),如果将位图设置为背景,则通常返回BitmapDrawable;如果将颜色设置为背景,则返回ColorDrawable。

ColorDrawable colorDrawable = (ColorDrawable) button.getBackground();

colorDrawable.setAlpha(125);

这将工作得很好。

静态方式:

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13627518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档