Example of adding the B4J ColorPicker View to the Top-Toolbar of the HTML Editor View.
Requires the library JavaObject.
The selected color is copied to the clipboard, use Paste to insert into HTML text.
Project attached, plus another example showing Hyperlink Button.
Add the ColorPicker at AppStart.
Sub to add the ColorPicker.
Handle color selection.
The HexRGB value is copied to the clipboard. Insert into the text by pasting.
Screenshot
Note
The solution open for enhancements, e.g.
Requires the library JavaObject.
The selected color is copied to the clipboard, use Paste to insert into HTML text.
Project attached, plus another example showing Hyperlink Button.
Add the ColorPicker at AppStart.
B4X:
Sub AppStart (Form1 As Form, Args() As String)
...
' Use callsubdelayed to add the button to the right of the top-toolbar
CallSubDelayed(Me, "AddColorPicker")
...
B4X:
Sub AddColorPicker
Dim joHE As JavaObject = HTMLEditor1
Dim joTB As JavaObject = joHE.RunMethod("lookup", Array(".top-toolbar"))
Dim tbColorPicker As ColorPicker
tbColorPicker.Initialize("tbColorPicker")
tbColorPicker.ToolTipText = "Select & copy color hex value."
tbColorPicker.PrefHeight = 26
' Set the prefwidth. Default is 52. If making wider, e.g. 150 the color value is also shown
tbColorPicker.PrefWidth = 52
joTB.RunMethodJO("getItems", Null).RunMethod("add", Array(tbColorPicker))
End Sub
The HexRGB value is copied to the clipboard. Insert into the text by pasting.
B4X:
Sub tbColorPicker_ValueChanged (Value As Paint)
Dim ColorInt As Int = fx.Colors.To32Bit(Value)
Dim HexARGB As String = Bit.ToHexString(ColorInt)
Dim HexRGB As String = HexARGB.SubString2(2,8)
fx.Clipboard.SetString($"#${HexRGB}"$)
End Sub
Screenshot
Note
The solution open for enhancements, e.g.
- creating an event to insert the colorvalue when the colorpicker dialog closes.
- Other buttons, like add hyperlink, file open / save.