如何以编程方式更改渐变的startColor属性-Android [英] How to programatically change the startColor attribute of gradient - Android

查看:344
本文介绍了如何以编程方式更改渐变的startColor属性-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在布局中使用的形状.我希望在活动中以编程方式更改颜色.

I have a shape that I'm using in a layout. I want the color to be programmatically changed in my 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"属性?

Is there any way I could change the "startColor" and "endColor" attributes in my Activity?

推荐答案

检查

Check this out, there's quite a bit of additional code but it seems to demonstrate how to create a drawable and gradient drawable in code... look around line 159. You may not need to create the shape in XML as you will probably need to progmatically create the shape etc

这篇关于如何以编程方式更改渐变的startColor属性-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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