Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

shape - How to programatically change the startColor attribute of gradient - 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>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...