B4A Library [Class] Custom Toast Messages

Hello All,

Updated: [June 30th, 2012]. Added more functions to set options for a new ToastShow and added sound. All are
attached below. NOTE: The new one requires the Audio library and only two parameters to be passed! See Post #: 11
for more information.

Updated: [June 24th, 2012] and added support for 9 Patch Images. The original is unchanged and both are attached below.


Here is a custom toast message class. It allows a number of features over the standard toast message. Below is a list of what can be set in this custom toast message class:

The message. It will wrap the message if it is longer than one line.
The text size
The text color
The message background color if no image is used
The toast message background image
The vertical position
The horizontal position
The number of seconds to display
Can be closed immediately in code
Select auto close or close by Tapping the message

Uses the new Reflection library 2.20.
Version 1.0 is attached to this post with Demo Code.

Margret

Erel the new B4A classes are awesome!!:)
 

Attachments

  • CToastClass.zip
    14.1 KB · Views: 1,769
  • CToast_9Patch.zip
    19.1 KB · Views: 1,088
  • CToast_9PatchSound.zip
    20.4 KB · Views: 1,133
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Hi.

Your class, which for me would be useful to be able to close a toast, interferes with IME lib. (IME disturbs often).

I use the IME to make visible an EditText that has the focus,
and this works well, but, if I use your class, the EditText is covered by the keyboard.
 

metrick

Active Member
Licensed User
Longtime User
Fatal signal 11 (SIGSEGV)

I wondered if anyone had come across this error please? It occurs with CToast but not Toast, crashing the app randomly on 4.2.2 but not, seemingly, 2.3.6.
I have the same problem with 4.2.2.
 

margret

Well-Known Member
Licensed User
Longtime User
Hi.

Your class, which for me would be useful to be able to close a toast, interferes with IME lib. (IME disturbs often).

I use the IME to make visible an EditText that has the focus,
and this works well, but, if I use your class, the EditText is covered by the keyboard.

Can you post a cut down version of the project that shows this? If so, I will be glad to look at it.
 

Dave O

Well-Known Member
Licensed User
Longtime User
Hi Margret,

Thanks for this handy (and blissfully small) class. I needed a toast that could be closed on demand (because the normal toast gets behind if you have quick successive actions), and this does the job nicely.

I also tweaked the code to let me specify corner radius and border color as arguments, which makes it look a bit more like the standard toast:

B4X:
Sub ToastMessageShow2(..., Tradius As Int)
...
  If Timage <> "" Then
     ...
   Else
     Dim panelDrawable As ColorDrawable
     panelDrawable.Initialize2(Tbackcolor, Tradius, 1, Colors.LightGray)
     TMS2pan.Background = panelDrawable
   End If
...

Thanks again!
 
Last edited:
Top