Android Code Snippet [DSE] [B4A] Standard Tooltips for Android 8+

Based on @Dave O 's code in this thread, here is a Designer script extension to add standard tooltips for Android 8+

B4X:
'Parameters: Text As String, 1 view
'Code in DesignerScript:{class}.SetTooltip("Tooltip", Button1)
Public Sub SetTooltip(DesignerArgs As DesignerArgs)
    Dim p As Phone
    If p.SdkVersion >= 26 Then
        Dim Text As String = DesignerArgs.Arguments.Get(0)
        Dim viewJO As JavaObject = DesignerArgs.GetViewFromArgs(1)
        viewJO.RunMethod("setOnLongClickListener", Array As Object(Null))   'remove any longClick listener
        viewJO.RunMethod("setTooltip", Array As Object(Text))
    End If
End Sub

Then just add the code to the designer script for your layout.

Code in DesignerScript: {class}.SetTooltip("Tooltip", Button1)

{class} is wherever you put the sub, it can go in any class you like. It can go in B4xMainPage, or an existing Utils class if you have one, or it's own separate class.
 
Last edited:
Top