• We just launched and are currently in beta. Join us as we build and grow the community.

Android Color Dialog Tutorial using Basic4Android

hate

Blue Team Operator
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
87
Likes
56
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial, I will introduce another kind of dialog, the Color Dialog. 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.

Here's the full code for this:
  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. End

    Sub

  5. Sub

    Globals
  6. 'These global variables will be redeclared each time the activity is created.
  7. 'These variables can only be accessed from this module.

  8. Dim

    Button1 As

    Button
  9. Dim

    bmp As

    Bitmap
  10. End

    Sub

  11. Sub

    Activity_Create(FirstTime As

    Boolean

    )
  12. 'Do not forget to load the layout file created with the visual designer. For example:
  13. 'Activity.LoadLayout("Layout1")
  14. Activity.LoadLayout("Main"

    )
  15. bmp.InitializeSample(File.DirAssets, "bermoy.jpg"

    ,48,48)
  16. Activity.Title = "Color Dialog - Lyndon Bermoy"

  17. End

    Sub

  18. Sub

    Activity_Resume

  19. End

    Sub

  20. Sub

    Activity_Pause (UserClosed As

    Boolean

    )

  21. End

    Sub

  22. Sub

    Button1_Click
  23. Dim

    cd As

    ColorDialog
  24. Dim

    color As

    Int
  25. Dim

    ret As

    Object
  26. cd.RGB = Colors.RGB(128, 128, 128)
  27. ret = cd.Show("B4A Color Dialog"

    , "Yes"

    , "No"

    , "Maybe"

    , bmp)
  28. ToastMessageShow(ret & " : "

    & cd.Red & " "

    & cd.Green & " "

    & cd.Blue, False

    )
  29. Activity.color = cd.RGB
  30. End

    Sub

Note:
cd - used as my variable for ColorDialog
color - used as my variable for Int
ret - used as my variable for Object
cd.RGB = Colors.RGB(128, 128, 128)- a syntax used to declare an RGB Color (Red,Blue,Green). 128 is the default color for Red, as well as the Green and color Blue.
Activity.color = cd.RGB - syntax used that after clicking the button, it will set the RGB color you set and it will be the background 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


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,517

323,526

Top