我正在尝试制作一个XML圆形按钮,以渐变颜色填充。此颜色需要以编程方式更改。
这里是我要实现的目标的一个示例。
我为构建此对象所做的尝试最终以渐变背景和纯色圆圈结束。而不是渐变圆和透明背景。
我希望能够同时使用2种以上的颜色或圆形的径向渐变。非常感谢您的帮助。
您可以尝试制作Drawable XML。范例
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="circle" >
<gradient
android:angle="90"
android:centerColor="#555994"
android:endColor="#b5b6d2"
android:startColor="#555994"
android:type="linear" />
</shape>
根据您的要求安排角度。
如果您希望通过编程方式更改颜色,请阅读以下内容:-
How do I programmatically set the background color gradient on a Custom Title Bar?
迟来了,但可能对其他人有帮助
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient android:angle="0" android:endColor="#fff" android:gradientRadius="@dimen/_30sdp" android:startColor="@color/colorPrimaryDark" android:type="radial" />
<size android:width="@dimen/_25sdp" android:height="@dimen/_25sdp" />
</shape>
</item>