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.

Requirements
  • B4A 6.0 or above
  • Compatible with API version 13 and up (set minSdkVersion to 13)
  • Android Support Repository
  • AppCompat library should be used.
Installation
  • 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.
Usage
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:

B4X:
Sub SomeSub
    [...]
    Dim Builder as MaterialDialogBuilder

    Builder.Initialize("CustomViewDialog")
    Builder.CustomView(False, 300dip)
    Builder.PositiveText("Ok").NegativeText("Cancel")
    Builder.Show
    [....]
End Sub

Sub CustomViewDialog_CustomViewReady (Dialog As MaterialDialog, CustomView As Panel)
    'Load your layout here or add it manually to the panel.
    CustomView.LoadLayout("customdialoglayout")
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:
B4X:
'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

    Activity.LoadLayout("layout1")

    Manager.Initialize("DialogManager")

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

    Dim Builder As ColorChooserDialogBuilder
    
    Builder.Initialize
    Builder.PreSelect(primaryColor)
    Builder.Show
End Sub

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



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

Attachments

  • MaterialDialogsLib1_0.zip
    305.3 KB · Views: 1,831
  • MaterialDialogsExample1_0.zip
    29.1 KB · Views: 1,633
Last edited:

rraswisak

Active Member
Licensed User
Longtime 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)
 

roberto64

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
B4X:
Dim cursor1 As Cursor
    Dim Fraz As  List
    Fraz.Initialize
    DM.InalizzaDb
    Builder.Initialize("Dialog4")
   
    Builder.Title("Frazionamento")
   
    cursor1 = DM.SQL.ExecQuery("Select Frazionamento FROM " & DM.DbTabFrazionamento)
    If cursor1.RowCount > 0 Then
        For i = 0  To cursor1.RowCount - 1
            cursor1.Position = i
Fraz.Add(cursor1.GetString("Frazionamento"))
        Next  
    End If
    Builder.Items(Array As String(Fraz))

    Builder.PositiveText("Ok")
    Builder.itemsCallbackSingleChoice(0)
    Builder.Show

    Fraz.Clear
 
Last edited:

corwin42

Expert
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.
 

red30

Well-Known 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.
 

syerif

Active Member
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?
 
Top