Syntax for colorpickerdialog

jschuchert

Active Member
Licensed User
Longtime User
I am trying to give my users the opportunity to set the background color for each of several activities. I intend to have a button available that triggers the color picker dialog from which they choose a color. However, I am not sure of the correct syntax. I have declared "cp as colorpickerdialog", "cd as colordialog" and tried to display the dialog using cp.show with its parameters but nothing happens. Not really sure what the 'title' should be. "ColorPickerDialog" didn't work. I have unsuccessfully searched for real world examples so am hoping someone would be kind enough to post some code to get me started.

For dunces like me (or maybe I am the only one) it would be so helpful to include code snippets during or at the conclusion of a topic. I learned long ago to never 'assume' the reader or listener had understood. Thanks to all for your time and patience.

Jim
 

jschuchert

Active Member
Licensed User
Longtime User
Thank you very much for your prompt reply. After some searching I found the 'demo' file you made and think I might have seen this before. I have now saved it so can use it for other dialogs. This is the kind of help I was referring to in my previous post.

Jim
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
I've been experimenting with the dialog and haven't had much luck with selecting a color for the activity background. I know it can be set with "activity.color=colors.<somecolor>" but haven't figured out how to so anything with the color I select with "Yes" from the dialog.
The following is essentially from the demo:
B4X:
Sub btnBGcolor_Click
   Dim cd As ColorPickerDialog
   Dim color As Int   'not used anywhere?
   cd.RGB = Colors.DarkGray  
   ret = cd.Show("B4A ColorPicker Dialog", "Yes", "No", "Maybe", Null)   
   ToastMessageShow(ret & " : " & cd.RGB, true)
        " -1:167,769,61" 'is the toastmessage returned added by me
activity.color=colors.??????? 'added by me
End Sub

I assume the toastmessage shows the returned RGB values so IF I could capture them, I could use "activity.color=colors.RGB(R,G,B values) for the background. However, my tests indicated the RGB values did not relate with the color I selected from the picker (blue was fuchsia). So how is a color captured and then how to use it. Am I making this much harder than it really is? Thanks.

Jim
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Am I making this much harder than it really is?
Probably. I don't see why you should be having problems, this works for me in the demo.

B4X:
Sub btnColor2_Click
   Dim cd As ColorPickerDialog
   Dim color As Int
   cd.RGB = Colors.DarkGray
   ret = cd.Show("B4A ColorPicker Dialog", "Yes", "No", "Maybe", Bmp)   
   ToastMessageShow(ret & " : " & cd.RGB, False)
   Activity.Color = cd.RGB
End Sub
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Thank you very much, Andrew. My syntax was wrong. I kept wanting to put "colors" prior to "rgb". I can move forward now. Incidentally, I really appreciate your 'file dialog'. It solved my problem of how a user would keep track of files previously used. Have a wonderful day.

Jim
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
choose color without clicking OK afterward?

Hi there,

I'm currently using the ColorPickerDialog, showing an OK and Cancel button.

Currently, the user taps a color, then clicks OK. Is there a way to remove the OK step, so the user just taps the color and the dialog closes? (I've seen some Android pickers work like this, and I think it feels a lot better.)

I tried a null string as the positive argument, but that didn't work.

Any ideas? Thanks!
 
Upvote 0
Top