Android 按钮背景色 [英] Android button background color

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

问题描述

我正在尝试在我的应用程序中设置按钮的背景颜色,但无法达到我想要的结果...

I am trying to set the background color of a button in my app and I am unable to achieve the result that I want...

我要设置的颜色是 holo_green_light(#ff99cc00).为了做到这一点,我使用 setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);

The color that I am trying to set is holo_green_light(#ff99cc00). In order to do it, I am using setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);

我得到的颜色不是 holo_green_light,而是浅灰色和 holo_green_light 的混合.

The color that I get is not the holo_green_light but a mix of lightgrey and holo_green_light.

我曾尝试使用 LightingColorFilter 并没有取得多大成功.

I have tried using the LightingColorFilter without much success.

有没有办法以编程方式执行此操作,使按钮看起来像一个按钮,而不是具有我需要的颜色的平面矩形.

Is there a way to do it programatically, so that the button appears like a button and not a flat rectangle with the color that I need.

推荐答案

如果你想保持一般样式(圆角等)而只是改变背景颜色,那么我使用 backgroundTint 属性

If you want to keep the general styling (rounded corners etc.) and just change the background color then I use the backgroundTint property

android:backgroundTint="@android:color/holo_green_light"

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

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