Android Color Dialog Tutorial using Basic4Android
Submitted by donbermoy on Tuesday, January 21, 2014 - 22:12.
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:
I have initialized bmp as Bitmap because I wanted to have an icon to my ColorDialog.
Here's the full code for this:
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
- Sub Globals
- 'These global variables will be redeclared each time the activity is created.
- 'These variables can only be accessed from this module.
- Dim Button1 As Button
- Dim bmp As Bitmap
- End Sub
- Sub Process_Globals
- 'These global variables will be declared once when the application starts.
- 'These variables can be accessed from all modules.
- End Sub
- Sub Globals
- 'These global variables will be redeclared each time the activity is created.
- 'These variables can only be accessed from this module.
- Dim Button1 As Button
- Dim bmp As Bitmap
- End Sub
- Sub Activity_Create(FirstTime As Boolean)
- 'Do not forget to load the layout file created with the visual designer. For example:
- 'Activity.LoadLayout("Layout1")
- Activity.LoadLayout("Main")
- bmp.InitializeSample(File.DirAssets, "bermoy.jpg",48,48)
- Activity.Title = "Color Dialog - Lyndon Bermoy"
- End Sub
- Sub Activity_Resume
- End Sub
- Sub Activity_Pause (UserClosed As Boolean)
- End Sub
- Sub Button1_Click
- Dim cd As ColorDialog
- Dim color As Int
- Dim ret As Object
- cd.RGB = Colors.RGB(128, 128, 128)
- ret = cd.Show("B4A Color Dialog", "Yes", "No", "Maybe", bmp)
- ToastMessageShow(ret & " : " & cd.Red & " " & cd.Green & " " & cd.Blue, False)
- Activity.color = cd.RGB
- End Sub
Add new comment
- 123 views