如何渐变填充按钮的背景吗? [英] How to gradient fill a button's background?
问题描述
我要创建一个彩色按钮与渐变填充(沿Y轴按钮的中间开始)。如果我设置按钮,我想要的颜色的背景属性,我失去的圆形的外观和按键的手感也渐变填充(它看起来像一个的TextView
与背景)。
I have to create a colored button with gradient fill(starting from the middle of the button along Y axis). If I set the background property of the button to the color I want, I lose the rounded look and feel of a button and also the gradient fill(It looks like a TextView
with a background).
另外,我想,当用户去presses按钮这种颜色改变。我可以通过选择XMLS指定本(颜色状态列表的)?
Also, I want this color to change when the user depresses the button. Can i specify this via selector XMLs(Color State Lists)?
任何教程或链接,可以帮助我在这里是AP preciated。
Any tutorials or links that can help me here is appreciated.
感谢。
推荐答案
<一个href="http://stackoverflow.com/questions/2173936/how-to-set-background-color-of-a-view">http://stackoverflow.com/questions/2173936/how-to-set-background-color-of-a-view
您需要定义一个自定义的 StateListDrawable
的资源,从一个Android使用的默认按钮,在这里你改变了九片图像是梯度也许克隆。你也许可以定义这些梯度XML,这意味着它们将延伸得很好。
You will need to define a custom StateListDrawable
resource, cloned perhaps from the one Android uses for buttons by default, where you change the nine-patch images to be gradients. You might be able to define those gradients in XML, which would mean they would stretch nicely.
这篇关于如何渐变填充按钮的背景吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!