Android Question GradientDrawable with 3 colors

DavideV

Active Member
Licensed User
Longtime User
Hi developers,
for my own colorpicker i need to create a colordrawable for an horizontal bar that shows the picked color as central color , the white color to left and black to right.
As you know the colordrawable uses only 2 colors so i made 2 panels one near the other: the panel to the left shows the picked color gradient to white and the right panel shows the picked color gradient to black (see images)

I would like to make only one panel to let the user choose the final color but i don't know how to do this.
Also a way to merge the 2 gradient into one bitmap/canvas will be good enought, so i'll load the bitmap into one panel.

Thanks in advance
DavideV
 

Attachments

  • Screenshot_2017-06-15-07-49-06.png
    Screenshot_2017-06-15-07-49-06.png
    93.2 KB · Views: 279
  • Screenshot_2017-06-15-07-49-30.png
    Screenshot_2017-06-15-07-49-30.png
    100.4 KB · Views: 306

Star-Dust

Expert
Licensed User
Longtime User
Do not you think I understand what you want to get?
The bar to increase or decrease the brightness?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You can have more than 2 colors in a GradientDrawable!
B4X:
Sub Globals
    Private pnlTest As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlTest.Initialize("")
    Activity.AddView(pnlTest, 20dip, 20dip, 256dip, 50dip)
  
    Private gdb As GradientDrawable
    Private GradColors(3) As Int = Array As Int(Colors.White, Colors.Red , Colors.Black)
    gdb.Initialize("LEFT_RIGHT", GradColors)
  
    pnlTest.Background= gdb
End Sub
And the result.

upload_2017-6-15_10-30-33.png
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Interesting, I did not think so. I use another solution, but yours is more interesting
 
Upvote 0

DavideV

Active Member
Licensed User
Longtime User
You can have more than 2 colors in a GradientDrawable!
B4X:
Sub Globals
    Private pnlTest As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlTest.Initialize("")
    Activity.AddView(pnlTest, 20dip, 20dip, 256dip, 50dip)
  
    Private gdb As GradientDrawable
    Private GradColors(3) As Int = Array As Int(Colors.White, Colors. , Colors.Black)
    gdb.Initialize("LEFT_RIGHT", GradColors)
  
    pnlTest.Background= gdb
End Sub
And the result.

View attachment 56690

Works fine, i didn't know that it support more colors.
Thanks again :)
 
Upvote 0
Top