圆形按钮的android更改背景颜色 [英] Change background color of circular button android

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

问题描述

我在android的一个按钮,我已经取得了圆形。另外我有一个它改变的pressed背景色XML,但颜色又回到正常的pressed状态改变后。

I have a button in android which I have made circular in shape. Also I have an xml which changes the background color on pressed, but the color goes back to normal after the pressed state is changed.

我做了如下修改code

I made the following change to code

arg0.setBackgroundColor(getResources()的getColor(R.color.greenText));

arg0.setBackgroundColor(getResources().getColor(R.color.greenText));

但现在的背景需要矩形形状,而不是椭圆形。

But now the background takes rectangular shape and not the oval shape.

推荐答案

在使用 setBackgroundColor ,我认为这里是你想要的好正如你所说的背景形状的变化,

Okay as you have said the background shape changes when using setBackgroundColor, i think here's what you want,

1。你可能有兴趣在这样的彩色滤光片

1.you might be interested in color filters like this

Button btn = (Button) findViewById(R.id.button1);
btn.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000));

您使用根据自己的需要在不同的价值观colour.If你想知道的颜色常数值,可以参照的文件的。

You use different values according to your required colour.If you want to know the constant values of colours, you can refer the documents.

2。你可以通过编程设定使用PorterDuff乘法模式下,整个按钮的阴影。这将改变按钮的颜色,而不是仅仅色调。

2.you can programmatically set the shade of the entire button using the PorterDuff multiply mode. This will change the button colour rather than just the tint.

例如为一个红色的阴影按钮

For example for a red shaded button

btn.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY);

有关绿色的阴影键

btn.getBackground().setColorFilter(0xFF00FF00, PorterDuff.Mode.MULTIPLY);

所以on.What它实际上做的是,它的工作原理是通过你的颜色值乘以当前按钮颜色值。

And so on.What it actually does is, it works by multiplying the current button colour value by your colour value.

3,你还可以用像这款Android按钮制作来定制你的按钮,使用机器人:背景=@可绘制/ custom_btn在布局(在标签内)来定义自定义按钮

3.You can also use an online tool like this Android Button Maker to customize your button and use android:background="@drawable/custom_btn" in your layout(inside the tag) to define the customized button.

现在我相信有更多的方式来实现你想要的,但我认为这些都是一些容易和快速修复功能可以use.Hope这会有所帮助。

Now i believe there are more ways to achieve what you want but i think these are some easy and quick fixes you can use.Hope this helps.

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

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