【问题标题】:XML Circle with gradient fill Android带有渐变填充 Android 的 XML Circle
【发布时间】:2015-09-29 11:38:11
【问题描述】:

我正在尝试制作一个 XML 按钮,圆形,填充渐变色。需要以编程方式更改此颜色。

这是我想要实现的一个示例。

我尝试构建它的结果是渐变背景和纯色圆圈。而不是渐变圆和透明背景。

我希望能够为圆使用超过 2 种颜色或径向渐变。非常感谢任何帮助。

【问题讨论】:

    标签: android android-layout gradient android-drawable xml-drawable


    【解决方案1】:

    您可以尝试制作可绘制的 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?

    【讨论】:

    • 有没有一种叫做圆的形状?
    【解决方案2】:

    迟到但可以帮助别人

    <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>
    

    输出

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 2011-08-22
      • 1970-01-01
      • 2023-03-19
      • 2012-01-02
      • 1970-01-01
      • 2019-04-23
      相关资源
      最近更新 更多