This is a wrap for this github project. It is a completely new written wrap and it is similar to this library written by @tchart
The advantage of this wrap is that you, the developer, now have much less work to implement the material dialogs into your app.
Additional this wrap is more up-to-date and includes CustomView too.
Requirements:
- B4A 6+
- You app must be setup for AppCompat
MaterialDialogs
Author: DonManfred (wrapper)
Version: 1.13
As there is not much to say there is no example.
But basically the use of this lib is
Install:
- Copy the lib files to your additional libraries folder
- Copy the content of MaterialDialogsRES.zip to your projects root folder so that the folder are at the same place as the files folder of your project.
- Add these lines to your project
Note that you should start with Initialization on each to setup the defaults...
Some Examples:
SingleSelect:
Using the "Items" as Content:
Different Gravity for title and content
The advantage of this wrap is that you, the developer, now have much less work to implement the material dialogs into your app.
Additional this wrap is more up-to-date and includes CustomView too.
Requirements:
- B4A 6+
- You app must be setup for AppCompat
MaterialDialogs
Author: DonManfred (wrapper)
Version: 1.13
- MaterialDialog
Events:- onAny (action As String)
- onCancel ( As )
- onDismiss ( As )
- onInput (text As String)
- onItemsCB (v As View, index As Int, text As String)
- onKey (key As Int, event As String)
- onNegative (action As String)
- onNeutral (action As String)
- onPositive (action As String)
- onSelection (selected() As Integer, strings() As CharSequence)
- onShow ( As )
- onSingleChoiceSelect (v As View, index As Int, text As String)
- Initialize (EventName As String)
- IsInitialized As Boolean
- adapter (adapter As ListAdapter, callback As ListCallback) As MaterialDialogBuilder
Sets a custom {@link android.widget.ListAdapter} for the dialog's list
adapter: The adapter to set to the list.
callback: The callback invoked when an item in the list is selected.
Return type: @return:This Builder object to allow for chaining of calls to set methods - alwaysCallInputCallback As MaterialDialogBuilder
- alwaysCallMultiChoiceCallback As MaterialDialogBuilder
By default, the multi choice callback is only called when the user clicks the positive button
or if there are no buttons. Call this to force it to always call on item clicks even if the
positive button exists.
Return type: @return:The Builder instance so you can chain calls to it. - alwaysCallSingleChoiceCallback As MaterialDialogBuilder
By default, the single choice callback is only called when the user clicks the positive button
or if there are no buttons. Call this to force it to always call on item clicks even if the
positive button exists.
Return type: @return:The Builder instance so you can chain calls to it. - autoDismiss (dismiss As Boolean) As MaterialDialogBuilder
This defaults to true. If set to false, the dialog will not automatically be dismissed
when an action button is pressed, and not automatically dismissed when the user selects
a list item.
dismiss: Whether or not to dismiss the dialog automatically.
Return type: @return:The Builder instance so you can chain calls to it. - backgroundColor (color As Int) As MaterialDialogBuilder
- backgroundColorRes (colorRes As String) As MaterialDialogBuilder
- btnSelector (selectorRes As String) As MaterialDialogBuilder
- btnSelectorStacked (selectorRes As String) As MaterialDialogBuilder
- btnStackedGravity (gravity As GravityEnum) As MaterialDialogBuilder
Sets the gravity used for the text in stacked action buttons. By default, it's #{@link GravityEnum#END}.
gravity: The gravity to use.
Return type: @return:The Builder instance so calls can be chained. - build As MaterialDialog
- buttonRippleColor (color As Int) As MaterialDialogBuilder
- buttonRippleColorAttr (colorAttr As Int) As MaterialDialogBuilder
- buttonRippleColorRes (colorRes As String) As MaterialDialogBuilder
- buttonsGravity (gravity As GravityEnum) As MaterialDialogBuilder
- cancelable (cancelable As Boolean) As MaterialDialogBuilder
- canceledOnTouchOutside (canceledOnTouchOutside As Boolean) As MaterialDialogBuilder
- content (content As CharSequence) As MaterialDialogBuilder
- contentColor (color As Int) As MaterialDialogBuilder
- contentColorAttr (colorAttr As Int) As MaterialDialogBuilder
- contentColorRes (colorRes As String) As MaterialDialogBuilder
- contentGravity (gravity As GravityEnum) As MaterialDialogBuilder
- contentLineSpacing (multiplier As Float) As MaterialDialogBuilder
- contentRes (contentRes As String) As MaterialDialogBuilder
- customView (view As View, wrapInScrollView As Boolean) As MaterialDialogBuilder
- dividerColor (color As Int) As MaterialDialogBuilder
- dividerColorRes (colorRes As String) As MaterialDialogBuilder
- forceStacking (stacked As Boolean) As MaterialDialogBuilder
- icon (icon As Drawable) As MaterialDialogBuilder
- iconAttr (iconAttr As Int) As MaterialDialogBuilder
- iconRes (icon As String) As MaterialDialogBuilder
- input (hint As CharSequence, prefill As CharSequence) As MaterialDialogBuilder
- input2 (hint As CharSequence, prefill As CharSequence, allowEmptyInput As Boolean) As MaterialDialogBuilder
- inputMaxLength (maxLength As Int) As MaterialDialogBuilder
- inputMaxLengthRes (maxLength As Int, errorColor As String) As MaterialDialogBuilder
- inputRange (minLength As Int, maxLength As Int) As MaterialDialogBuilder
- inputRangeRes (minLength As Int, maxLength As Int, errorColor As String) As MaterialDialogBuilder
Same as #{@link #inputRange(int, int, int)}, but it takes a color resource ID for the error color. - inputType (type As Int) As MaterialDialogBuilder
- itemColor (color As Int) As MaterialDialogBuilder
Renamed to {@link #itemsColor(int)} for consistency. - itemColorAttr (colorAttr As Int) As MaterialDialogBuilder
Renamed to {@link #itemsColorAttr(int)} for consistency. - itemColorRes (colorRes As String) As MaterialDialogBuilder
Renamed to {@link #itemsColorRes(int)} for consistency. - items (collection() As String) As MaterialDialogBuilder
- itemsCallback As MaterialDialogBuilder
- itemsCallbackMultiChoice (selectedIndices() As Integer) As MaterialDialogBuilder
Pass null for the selected indices to leave all options unselected initially. Otherwise pass
an array of indices that will be selected initially.
selectedIndices: The radio button indices that will be selected initially.
callback: The callback that will be called when the presses the positive button.
Return type: @return:The Builder instance so you can chain calls to it. - itemsCallbackSingleChoice (selectedIndex As Int) As MaterialDialogBuilder
Pass anything below 0 (such as -1) for the selected index to leave all options unselected initially.
Otherwise pass the index of an item that will be selected initially.
selectedIndex: The checkbox index that will be selected initially.
callback: The callback that will be called when the presses the positive button.
Return type: @return:The Builder instance so you can chain calls to it. - itemsColor (color As Int) As MaterialDialogBuilder
- itemsColorAttr (colorAttr As Int) As MaterialDialogBuilder
- itemsColorRes (colorRes As String) As MaterialDialogBuilder
- itemsGravity (gravity As GravityEnum) As MaterialDialogBuilder
- itemsIds (idsArray() As Int) As MaterialDialogBuilder
- itemsRes (itemsRes As String) As MaterialDialogBuilder
- limitIconToDefaultSize As MaterialDialogBuilder
Limits the display size of a set icon to 48dp. - linkColor (color As Int) As MaterialDialogBuilder
- linkColor2 (colorStateList As ColorStateList) As MaterialDialogBuilder
- listSelector (selectorRes As String) As MaterialDialogBuilder
- maxIconSize (maxIconSize As Int) As MaterialDialogBuilder
- negativeColor (color As Int) As MaterialDialogBuilder
- negativeColorRes (colorRes As String) As MaterialDialogBuilder
- negativeText (message As CharSequence) As MaterialDialogBuilder
- negativeTextRes (negativeRes As String) As MaterialDialogBuilder
- neutralColor (color As Int) As MaterialDialogBuilder
- neutralColor2 (colorStateList As ColorStateList) As MaterialDialogBuilder
- neutralColorRes (colorRes As String) As MaterialDialogBuilder
- neutralText (message As CharSequence) As MaterialDialogBuilder
- neutralTextRes (neutralRes As String) As MaterialDialogBuilder
- positiveColor (color As Int) As MaterialDialogBuilder
- positiveColor2 (colorStateList As ColorStateList) As MaterialDialogBuilder
- positiveText (message As CharSequence) As MaterialDialogBuilder
- positiveTextRes (positiveRes As String) As MaterialDialogBuilder
- progress (indeterminate As Boolean, max As Int) As MaterialDialogBuilder
Makes this dialog a progress dialog.
indeterminate: If true, an infinite circular spinner is shown. If false, a horizontal progress bar is shown that is incremented or set via the built MaterialDialog instance.
max: When indeterminate is false, the max value the horizontal progress bar can get to.
Return type: @return:An instance of the Builder so calls can be chained. - progress2 (indeterminate As Boolean, max As Int, showMinMax As Boolean) As MaterialDialogBuilder
Makes this dialog a progress dialog.
indeterminate: If true, an infinite circular spinner is shown. If false, a horizontal progress bar is shown that is incremented or set via the built MaterialDialog instance.
max: When indeterminate is false, the max value the horizontal progress bar can get to.
showMinMax: For determinate dialogs, the min and max will be displayed to the left (start) of the progress bar, e.g. 50/100.
Return type: @return:An instance of the Builder so calls can be chained. - progressIndeterminateStyle (horizontal As Boolean) As MaterialDialogBuilder
By default, indeterminate progress dialogs will use a circular indicator. You
can change it to use a horizontal progress indicator. - progressNumberFormat (format As String) As MaterialDialogBuilder
hange the format of the small text showing current and maximum units of progress.
The default is "%1d/%2d". - progressPercentFormat (format As NumberFormat) As MaterialDialogBuilder
Change the format of the small text showing the percentage of progress.
The default is NumberFormat.getPercentageInstance(). - show As MaterialDialog
- theme (theme As Theme) As MaterialDialogBuilder
- title (title As CharSequence) As MaterialDialogBuilder
- titleColor (color As Int) As MaterialDialogBuilder
- titleColorAttr (colorAttr As Int) As MaterialDialogBuilder
- titleColorRes (colorRes As String) As MaterialDialogBuilder
- titleGravity (gravity As GravityEnum) As MaterialDialogBuilder
- typeface (medium As Typeface, regular As Typeface) As MaterialDialogBuilder
Sets the fonts used in the dialog. It's recommended that you use {@link #typeface(String, String)} instead,
to avoid duplicate Typeface allocations and high memory usage.
medium: The font used on titles and action buttons. Null uses device default.
regular: The font used everywhere else, like on the content and list items. Null uses device default.
Return type: @return:The Builder instance so you can chain calls to it. - typefacebyString (medium As String, regular As String) As MaterialDialogBuilder
Sets the fonts used in the dialog, by file names. This also uses TypefaceHelper in order
to avoid any un-needed allocations (it recycles typefaces for you).
medium: The name of font in assets/fonts used on titles and action buttons (null uses device default). E.g. [your-project]/app/main/assets/fonts/[medium]
regular: The name of font in assets/fonts used everywhere else, like content and list items (null uses device default). E.g. [your-project]/app/main/assets/fonts/[regular]
Return type: @return:The Builder instance so you can chain calls to it. - widgetColor (color As Int) As MaterialDialogBuilder
- widgetColorRes (colorRes As String) As MaterialDialogBuilder
As there is not much to say there is no example.
But basically the use of this lib is
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim dialog As MaterialDialog
End sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
dialog.Initialize("Dialog")
End Sub
Sub Button_Click
Log("Button_Click")
dialog.positiveText("Cool!").negativeText("Oh nooo").neutralText("I dont care").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("DonManfred presents").content("afollestad´s MaterialDialogs").iconRes("donmanfred").dividerColor(Colors.Cyan).autoDismiss(False).buttonRippleColor(Colors.Gray).show
End Sub
Install:
- Copy the lib files to your additional libraries folder
- Copy the content of MaterialDialogsRES.zip to your projects root folder so that the folder are at the same place as the files folder of your project.
- Add these lines to your project
B4X:
#AdditionalRes: ..\res.core
#AdditionalRes: ..\res.MaterialProgressBar
Note that you should start with Initialization on each to setup the defaults...
Some Examples:
B4X:
If dialog.isShowing Then
dialog.hide
End If
Dim items(3) As String
items(0) = "Hallo"
items(1) = "B4X"
items(2) = "World!"
dialog.Initialize("Dialog")
dialog.tag = CreateMap("action":"MultiSelect")
dialog.positiveText("Yo").negativeText("Oh nooo").neutralText("I dont care").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).content("test").contentLineSpacing(1).items(Array As String("Apple ", "Orange", "Grapes","Pineapple","Mango" )).itemColor(Colors.Blue).itemsCallbackMultiChoice(Array As Int(1,2)).alwaysCallMultiChoiceCallback.build.show
SingleSelect:
B4X:
If dialog.isShowing Then
dialog.hide
End If
dialog.Initialize("Dialog")
dialog.tag = CreateMap("action":"SingleSelect")
dialog.content("Test 5").items(Array As String("Apple ", "Orange", "Grapes","Pineapple","Mango" )).itemColor(Colors.Yellow).negativeText("Oh nooo").positiveText("OK").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).itemsCallbackSingleChoice(1).build.show
Using the "Items" as Content:
B4X:
If dialog.isShowing Then
dialog.hide
End If
dialog.Initialize("Dialog")
dialog.tag = CreateMap("action":"SingleSelect")
dialog.content("Test 5").items(Array As String("1. Do this", "2. and this", "3. yo, this too","4. one again","Last but not least" )).itemColor(Colors.Yellow).negativeText("Oh nooo").positiveText("OK").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("Hallo B4X-World :-)").titleGravity(2).itemsGravity(2).build.show
Different Gravity for title and content
B4X:
If dialog.isShowing Then
dialog.hide
End If
dialog.Initialize("Dialog")
dialog.tag = CreateMap("action":"SingleSelect")
dialog.content("Test 5").items(Array As String("1. Do this", "2. and this", "3. yo, this too","4. one again","Last but not least" )).itemColor(Colors.Yellow).negativeText("Oh nooo").positiveText("OK").positiveColor(Colors.Green).neutralColor(Colors.Magenta).negativeColor(Colors.Red).title("Hallo B4X-World :-)")).titleGravity(2).contentGravity(0).itemsGravity(1).build.show
Attachments
Last edited: