Italian posizionare toastmessage sul display

tmtube73

Active Member
Licensed User
con questo codice mostro un messaggio a video

B4X:
Sub ShowToastMessage(Msg As String)
    ToastMessageShow(Msg, True)
    Sleep(3000) 'message duration     
End Sub

il messaggio esce in basso al display, qualcuno sa dirmi che comando usare per centrare il messaggio nel display?

grazie.
 

Lello1964

Well-Known Member
Licensed User
Longtime User
io uso questo, provalo


B4X:
Sub ShowCustomToast(Text As Object, LongDuration As Boolean, BackgroundColor As Int)
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim duration As Int
    If LongDuration Then duration = 1 Else duration = 0
    Dim toast As JavaObject
    toast = toast.InitializeStatic("android.widget.Toast").RunMethod("makeText", Array(ctxt, Text, duration))
    Dim v As View = toast.RunMethod("getView", Null)
    Dim cd As ColorDrawable
    cd.Initialize(BackgroundColor, 20dip)
    v.Background = cd
    'uncomment To show toast in the center:
    toast.RunMethod("setGravity", Array( _
           Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL), 0, 0))
    toast.RunMethod("show", Null)
End Sub
 
Top