Mohammad Tahvildary
Mohammad Tahvildary

Reputation: 100

How can I create a Line with different colors in android

I want to create a line with different colors in two ways like:

1. ColorBar (preview)

Something like a progress bar but with different colors

2.Colorful Table (preview)

Something like a table but with different colors(not different cell background)

I want to for example write some code and say the min and max point of the periods and it show me the period in some color (like red) on a line.

so is there any way that I can draw them in my jar file?(I mean the jar file that is connected to activity like MainActivity.jar) I use Android Studio v 1.0.2

Thanks for your useful helps:)

Upvotes: 0

Views: 762

Answers (1)

JASON G PETERSON
JASON G PETERSON

Reputation: 2223

Use GradientDrawable.

GradientDrawable rainbow = new GradientDrawable(Orientation.LEFT_RIGHT,
            new int[] {Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED});

The docs tell you how to set shape, interpolation between colors, position of colors, etc.

Upvotes: 1

Related Questions