B4A Library Material Dialogs - Make your dialogs nice

I think this library is the third attempt in this forum to wrap the excellent afollestad Material Dialogs library.

The difference to the other library wrappers is that this one is (except of some minor features) a complete wrap including file- and folder choosers, color chooser and a complete wrap of the core material dialog including very well support fror custom layouts. Not wrapped are the preference dialogs (We have the Preferences library for this).

I think the library (and the API) now is quite stable. Nevertheless I call it "beta" because I might have overseen anything. Also there are a few bugs in the underlying library which I hope will be fixed soon.
Please report any bugs you find in this thread.

Basic.png Basic_List.png Multi_Choose.png Input_Number.png Progress.png Color_Chooser.png File_Chooser.png

Your Support
Creating libraries and wrappers for existing library projects is a lot of work. This one took an extra amouont of testing and debugging to get all the features running.
The use of this library is totally free and you even don't need to mention in your app that you use it.
But if you use this library in your projects and you think it is useful to you please consider to make a donation:

Thanks very much for your support.

  • B4A 6.0 or above
  • Compatible with API version 13 and up (set minSdkVersion to 13)
  • Android Support Repository
  • AppCompat library should be used.
  • Copy all files from the MaterialDialogsLibx_xx.zip file to your additional libraries folder. There are 6 files. 1 .xml, 1 .jar and 4 .aar files.
Please study the very detailed example for the usage of the dialogs. It covers most of the features of this library.

Using the CustomView method:
To display a cutom layout for your dialog use the MaterialDialogBuilder.CustomView(WrapInScrollView, Height). This adds a Panel to the dialog. The width of the dialog is defined in the material design guidelines and cannot be changed. The height can be defined freely. Optionally you can wrap your content in a ScrollView so that it is scrollable but this will add some margin to the content.

To add your content (manually or by loading a layout file) you have to use the CustomViewReady event. This event sub receives a Panel object to which your layout can be added. Here a short example for a CustomView:

Sub SomeSub
    Dim Builder as MaterialDialogBuilder

    Builder.CustomView(False, 300dip)
End Sub

Sub CustomViewDialog_CustomViewReady (Dialog As MaterialDialog, CustomView As Panel)
    'Load your layout here or add it manually to the panel.
End Sub

Using FileChooser, FolderChooser and ColorChooser dialogs:
These dialogs work a bit different than normal dialogs because the events must be handled directly by the activity.
First step is to extend the Activity from de.amberhome.materialdialogs.MaterialDialogsActivity. Then in Activity_Create initialize the MaterialDialogsManager. This Manager raises the events for the Dialogs. Here is a complete example for the ColorChooserDialog:
'Only needed for FileChooser, FolderChooser and ColorChooser dialogs
#Extends: de.amberhome.materialdialogs.MaterialDialogsActivity

Sub Globals
    Private Manager As MaterialDialogsManager
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim primaryColor As Int



    Dim ac As AppCompat
    primaryColor = ac.GetThemeAttribute("colorPrimary")

    Dim Builder As ColorChooserDialogBuilder
End Sub

Sub DialogManager_ColorSelected (Dialog As ColorChooserDialog, Color As Int)
    Log("Color Selected: " & Color)
End Sub

Version History
  • First public (beta) release.
  • Fix: CustomViews with ScrollView should work better.
  • Change: MaterialDialogs_CustomViewReady event changed its signature!
  • New: Base library updated to


  • MaterialDialogsLib1_0.zip
    305.3 KB · Views: 1,525
  • MaterialDialogsExample1_0.zip
    29.1 KB · Views: 1,338
Last edited:


Active Member
Licensed User
Hi Corwin,

I have been try the library, it's nice and work great.

Found a little bug at Folder dialog it show wrong folder name, when i select says folder at index 5 but the display always folder at index 4 (index -1)


Active Member
Licensed User
Longtime User
hi, is it possible, as per the code below, to load fields in a table and load it inside the MaterialDialogBuilder as per code?
thank you
Dim cursor1 As Cursor
    Dim Fraz As  List
    cursor1 = DM.SQL.ExecQuery("Select Frazionamento FROM " & DM.DbTabFrazionamento)
    If cursor1.RowCount > 0 Then
        For i = 0  To cursor1.RowCount - 1
            cursor1.Position = i
    End If
    Builder.Items(Array As String(Fraz))


Last edited:


Licensed User
Longtime User
Please ask questions in the questions section of the forum.
I can't answer every question personally so you will get answers faster if you ask in the questions forum.


Active Member
Licensed User
Longtime User
When you call Input Dialogs, a keyboard is displayed. Is it possible to show the keyboard only at the moment of the start of text input? That is, when I call Input Dialogs, the dialog itself is displayed without a keyboard, and when I want to enter text, only then display the keyboard.


Licensed User
Longtime User
i got this error
java.lang.ClassCastException: de.amberhome.materialdialogs.example.main cannot be cast to de.amberhome.materialdialogs.MaterialDialogsActivity

any sugestion?