Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
rjendeavours
Courses Plus Student 4,965 PointsWebKit Linear Gradient equivalent for Android (Java not XML)
Hi Guys,
You have the following code;
-webkit-linear-gradient(left, #64F6F6 51% , #FFF 51%);
If that was applied to a button it would look like half of the button is blue, half white, with no blending of the gradient between (a nice smooth line separating the colors).
First I want to be able to put this style on a button in Android via Java and not XML & then I will be changing the percentages every second.
I don't need help creating a method changing the percentage as I shall be doing this using runnable etc etc
What I would like to know is the syntax I need to use to put that exact gradient on the background of a button through Java(programmatically I think the term is called).
Then what would be the syntax to change the percentages inside the runnable.
i.e
// Change percentages on gradient MyButton.setBackground(awesomeGradient); // set new gradient to button background
I've looked at gradient drawables but I don't think I can access percentages nor achieve an "unblended " coming together of the colors.
In XML you can put a startcolor middle and end...so I'm sure java will have something.
Ideally if anyone has a simple approach that is like...webkit-linear etc....that would be awesome
Thanks
1 Answer
Ben Jakuben
Treehouse TeacherThere's an answer on StackOverflow that might help: http://stackoverflow.com/a/8780181/475217
I haven't done this, so I don't know if this specific solution will give you exactly what you need, but the basic idea seems to match what you are looking for. Hope it helps!
rjendeavours
Courses Plus Student 4,965 Pointsrjendeavours
Courses Plus Student 4,965 PointsHi Ben,
Thanks for the reply
I found this there too but I don't really get how it works. Plus it seems like an awful lot of code for the CSS/ Javascript equivalent.
Also I have no idea how to set the shader to the background of a button :/ Or then access the "percentages" in a timer when I want to change the proportions of the colors.
Any ideas? :)