android - 如何以编程方式更改渐变的 startColor 属性 - Android

标签 android shapes

我有一个要在布局中使用的形状。我希望在我的 Activity 中以编程方式更改颜色。

<shape android:id="@+id/shape1" xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
   <gradient android:id="@+id/gradient1"
        android:startColor="@color/widget_header"
        android:endColor="#0000CC" 
        android:angle="270"/> 

   <corners android:bottomRightRadius="1dp"
        android:bottomLeftRadius="1dp" 
        android:topLeftRadius="7dp"
        android:topRightRadius="7dp"/> 
</shape>

有什么方法可以更改 Activity 中的“startColor”和“endColor”属性?

最佳答案

检查 this out,有相当多的额外代码,但它似乎演示了如何在代码中创建可绘制对象和渐变可绘制对象...查看第 159 行。您可能不需要在 XML 中创建形状,因为您可能需要以编程方式创建形状等

关于android - 如何以编程方式更改渐变的 startColor 属性 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4762512/

相关文章:

c++ - 在任意原点调整矩形形状

c# - 在 Maui Blazor 上显示/隐藏虚拟键盘

Android - Canvas是如何使用的

android - 如何从对话框中删除边框?

Android - WebView 的问题

Android:图形shape.intersects方法。 android中有模拟吗?

android - 是否可以将位图的点作为路径?

java.lang.IllegalArgumentException : Cannot create PhoneAuthCredential without either verificationProof, session 信息,或临时证明

安卓/谷歌分析 SDK : how to make REAL TIME analytics working?

opencv - 在 OpenCV 中检测不完整的矩形(缺角/短边)