B4A Class TD_Toast

Name: TD_Toast
Type: custom B4A Class or b4xlib
Version: 1

This custom class subtitutes the standard android toast message. The benefits are:
  • Customizable GUI
  • Timed out Message or static until clicked
  • Inbuild Themes

Toast1.png
Theme Attention Toast
Toast2.png
Theme Info Toast
Toast3.png
Theme Question Toast,
Toast4.png
Theme SuccessToast
Toast5.png
Theme Error Toast
Toast6.png
Individual Toast
Toast7.png
Theme Loading Indicator Toast

  1. Download Example Project from here Download
  2. Install Class in your project or copy TD_Toast.b4xlib to your additional lib folder and activate lib in lib pane.
  3. Activate this libs B4XGifView, StringUtils, XUI
  4. Create a Reference in the Class_Globals of the page like Private TD_Toast1 as TD_Toast

Initialize the Toast object:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Sleep(0)
    
    '# Initialize Class
    '# Allways Me, Allways Root, eventname
    TD_Toast1.Initialize(Me,Root,"TD_Toast1")
End Sub

The Toast creates a Type Vaiable TDToast and a public Variable ToastGUI.
Type TDToast ( _
Category As String, Duration As Int, _
Width As Int, height As Int, Top As Int, Color As Int, _
Bordercolor As Int, Borderwidth As Int, Borderradius As Int, _
IconFile As String, IconWidth As Int, IconHeight As Int, _
Text As String, Textcolor As Int, Textsize As Int, _
click As Boolean)

The default duration for themed toasts is 3000ms. All needed Icons are inbuild.
Before shown the toast view is added to the parent (B4XPage) and it is removed if the the toast goes hidden.

To show the Toast:
TD_Toast1.showtoast
(Category As String, Text As String, IconFile As String,click As Boolean)

Category -Themed- : attention / info / error /question/sucess
Category -individual- : gray
Category -special - : spinner as loading indicator
Text: The text shown may be a single ore multiline text. CSBuilder recomended.
IconFile: Tehe Filename if categroy is gray otherwhise empty ""
click: If True the toast is displayed until it is clicked.

To hide the toast manually:
TD_Toast1.killToast

To customize the toast:
Before calling showToast set the individual values to the variable Public ToastGUI As TDToast (TD_Toast1.ToastGUI....)

To click the toast:
If you click on the Toast the custom event _click raises (TD_Toast1_Click)
If you customize the ToastGUI you will be able to make every toast static/clickable or not.
 

Attachments

  • TD_Toast.b4xlib
    243.9 KB · Views: 36
Top