Android Color Picker Dialog Tutorial using Basic4Android

Hi! The last time we had our tutorial is in the Color Dialog. Today i will introduce another kind of dialog that is similar in the Color Dialog in Android. First, you need to create one button and named it Button1. Next, named your layout name as "Main". Declare first your variable in the Sub_Global like this:
  1. Sub Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4. Dim Button1 As Button
  5. Dim bmp As Bitmap
  6. End Sub
I have initialized bmp as Bitmap because I wanted to have an icon to my ColorDialog. The difference of this Color Picker Dialog in the Color Dialog is that it can easily pick the color that you want and not to be able to adjust it. Here's the full code for this tutorial:
  1. Sub Process_Globals
  2. 'These global variables will be declared once when the application starts.
  3. 'These variables can be accessed from all modules.
  4.  
  5. End Sub
  6.  
  7. Sub Globals
  8. 'These global variables will be redeclared each time the activity is created.
  9. 'These variables can only be accessed from this module.
  10.  
  11. Dim Button1 As Button
  12. Dim bmp As Bitmap
  13. End Sub
  14.  
  15. Sub Activity_Create(FirstTime As Boolean)
  16. 'Do not forget to load the layout file created with the visual designer. For example:
  17. 'Activity.LoadLayout("Layout1")
  18. Activity.LoadLayout("Main")
  19. bmp.InitializeSample(File.DirAssets, "bermoy.jpg",48,48)
  20. Activity.Title = "Color Picker Dialog - Lyndon Bermoy"
  21.  
  22. End Sub
  23.  
  24. Sub Activity_Resume
  25.  
  26. End Sub
  27.  
  28. Sub Activity_Pause (UserClosed As Boolean)
  29.  
  30. End Sub
  31.  
  32. Sub Button1_Click
  33. Dim cd As ColorPickerDialog
  34. Dim color As Int
  35. cd.RGB = Colors.DarkGray
  36. ret = cd.Show("B4A ColorPicker Dialog", "Yes", "No", "Maybe", bmp)
  37. ToastMessageShow(ret & " : " & cd.RGB, False)
  38. Activity.color = cd.RGB
  39. End Sub
Note: cd - a variable used to initialized as an object of ColorPickerDialog. color - the variable used as the color in terms of integer value. cd.RGB = Colors.DarkGray - a syntax used in the default value of our RGB color that is in DarkGray. ret - our variable in object that is used for the input dialog in color. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer If you have some queries, feel free to contact the number or e-mail below. Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Comments

Add new comment