开源软件名称(OpenSource Name):michael-rapp/AndroidMaterialDialog开源软件地址(OpenSource Url):https://github.com/michael-rapp/AndroidMaterialDialog开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):AndroidMaterialDialog - README"AndroidMaterialDialog" is an Android-library, which provides builders for creating dialogs, which are designed according to Android 5's Material Design guidelines even on pre-Lollipop devices. The following screenshots show the appearances of dialogs, which have been created using the library. The library provides the following main features:
The project also includes an example application, which implements some example dialogs for demonstrating the use of the library. License AgreementThis project is distributed under the Apache License version 2.0. For further information about this license agreement's content please refer to its full version, which is available at http://www.apache.org/licenses/LICENSE-2.0.txt. Prior to version 3.1.1 this library was distributed under the GNU Lesser General Public License version 3.0 (GLPLv3). DownloadThe latest release of this library can be downloaded as a zip archive from the download section of the project's Github page, which is available here. Furthermore, the library's source code is available as a Git repository, which can be cloned using the URL https://github.com/michael-rapp/AndroidMaterialDialog.git. Alternatively, the library can be added to your Android app as a Gradle dependency by adding the following to the respective module's dependencies {
compile 'com.github.michael-rapp:android-material-dialog:5.2.3'
} Before version 2.0.0 this project was hosted on Sourceforge. These older versions used the legacy Eclipse ADT folder structure and are not available as Gradle artifacts. ExamplesIn the following a few examples, which illustrate the use of the library's most important features, are given. Moreover, this project contains the source code of an example app, which implements use cases of the library for demonstration purposes, as well as a more detailed documentation in the Wiki and auto-generated javadoc files. Since version 5.0.0 the library requires to use AndroidX instead of the older AppCompat support libraries. Make sure that you have migrated your app to AndroidX and that you are using one of the Material component themes instead of the AppCompat ones, e.g. Creating a typical alert dialogThe code below shows how to create and show an alert dialog by using the library's MaterialDialog.Builder dialogBuilder = new MaterialDialog.Builder(this);
dialogBuilder.setTitle(R.string.dialog_title);
dialogBuilder.setMessage(R.string.dialog_message);
dialogBuilder.setTitle(R.string.dialog_title);
dialogBuilder.setPositiveButton(android.R.string.ok, null);
dialogBuilder.setNegativeButton(android.R.string.cancel, null);
MaterialDialog dialog = dialogBuilder.create();
dialog.show(); The appearance of the dialog, which is created by the given sample code, is shown below: Using custom viewsIn order to adjust the appearance of a MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
builder.setView(R.layout.custom_dialog_content);
builder.setCustomTitle(R.layout.custom_dialog_title);
builder.setCustomMessage(R.layout.custom_dialog_message);
builder.setCustomButtonBar(R.layout.custom_dialog_button_bar);
builder.setCustomHeader(R.layout.custom_dialog_header); When using custom layouts, which contain views of the same type and being associated with the same id as the views in the original layout, the dialog's methods (e.g. the
An example, which uses custom views for displaying the title, message, content and buttons, is shown in the screenshot below. Creating a progress dialogThe following source code shows how a progress dialog, which displays a circular progress bar, can be created. Such as a regular ProgressDialog.Builder dialogBuilder = new ProgressDialog.Builder(this);
dialogBuilder.setTitle(R.string.dialog_title);
dialogBuilder.setMessage(R.string.dialog_message);
dialogBuilder.setPositiveButton(android.R.string.ok, null);
dialogBuilder.setNegativeButton(android.R.string.cancel, null);
dialogBuilder.setProgressBarPosition(ProgressBarPosition.LEFT)
ProgressDialog dialog = dialogBuilder.create();
dialog.show(); The screenshot below shows the appearance of a EditTextDialog.Builder dialogBuilder = new EditTextDialog.Builder(this);
dialogBuilder.setTitle(R.string.dialog_title);
dialogBuilder.setMessage(R.string.dialog_message);
dialogBuilder.setPositiveButton(android.R.string.ok, null);
dialogBuilder.setNegativeButton(android.R.string.cancel, null);
dialogBuilder.setText("Text");
EditTextDialog dialog = dialogBuilder.create();
dialog.show(); It is possible to add one or several Creating an edit text dialogThe following code illustrates how a dialog that contains an Creating a wizard dialogA WizardDialog.Builder dialogBuilder = new WizardDialog.Builder(this);
dialogBuilder.showHeader(true);
dialogBuilder.setHeaderBackground(R.drawable.header_background);
dialogBuilder.addFragment(R.string.fragment1_title, Fragment1.class);
dialogBuilder.addFragment(R.string.fragment2_title, Fragment2.class);
dialogBuilder.addFragment(R.string.fragment3_title, Fragment3.class);
dialogBuilder.setTabPosition(TabPosition.PREFER_HEADER);
dialogBuilder.enableTabLayout(true);
dialogBuilder.enableSwipe(true);
dialogBuilder.showButtonBar(true);
WizardDialog dialog = dialogBuilder.create();
dialog.show(); The following screenshot illustrates one possible appearance of a Showing a headerAll dialogs may contain a header, which consists of a background image or color and an optional icon. The following code shows how a dialog can be configured to contain such a header, once a builder has been instantiated like shown in the previous sections. ...
dialogBuilder.showHeader(true);
dialogBuilder.setHeaderBackground(R.drawable.header_background);
dialogBuilder.setHeaderIcon(R.drawable.header_icon);
... The picture below shows a dialog, which contains a header with a background image and an icon: Specifying scrollable areasIf the content of a dialog takes to much vertical space, it cannot completely be displayed on the screen anymore. This can especially be a problem in landscape mode, where only limited vertical space is available. To overcome this problem, the library allows to specify which areas of a dialog should be (vertically) scrollable. For example, to specify that the message of a dialog should be scrollable, the following code can be used: dialogBuilder.setScrollableArea(ScrollableArea.Area.MESSAGE); Each dialog consists of several areas, which are represented by the values of the enum
If multiple areas of a dialog should be scrollable, this can be achieved as shown below: dialogBuilder.setScrollableArea(ScrollableArea.Area.HEADER,
ScrollableArea.Area.CONTENT); The first area, which is provided to the method corresponds to the top area, which should be scrollable (inclusive). The second method parameter specifies the bottom area, which should be scrollable (also inclusive). Both specified areas, as well as all areas, which are located between them, are made scrollable by wrapping them in a single Using themesThe library comes with pre-defined dark and light theme variants. Furthermore three different fullscreen themes are available per variant. The following table shows the IDs of all themes. They can be referenced in XML using the syntax
In order to use one of the predefined themes, the id of the respective theme has to be passed as an argument to the constructor of the builder WizardDialog.Builder dialogBuilder = new WizardDialog.Builder(this, R.style.MaterialDialog_Light);
... As an alternative, the theme, which should be used by all of the library's builders by default, can be globally specified. This requires to include the theme attribute Moreover, it might be useful to extend the predefined themes in order to overwrite some theme attributes. One common use-case is to overwrite the theme attribute <resources>
<style name="AppTheme" parent="@style/Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item>
<item name="colorAccent">@color/color_accent</item>
<item name="materialDialogTheme">@style/CustomDialogTheme</item>
</style>
<style name="CustomDialogTheme" parent="@style/MaterialDialog.Light">
<item name="colorAccent">@color/color_accent</item>
</style>
</resources> The screenshots below show the appearance of dialogs, which use the themes Using animationsThe
FadeAnimation animation = new FadeAnimation.Builder(this).setAlpha(0f).setDuration(1000L).create();
RectangleRevealAnimation animation = new RectangleRevealAnimation.Builder(this).setX(0).setY(0).setWidth(0).setHeight(0).setDuration(1000L).create()
CircleRevealAnimation animation = new RectangleRevealAnimation.Builder(this).setX(0).setY(0).setRadius(0).setDuration(1000L).create(); A dialog, which is shown and hidden using a In the following a dialog, which is shown and hidden using a Besides using animations to show or hide dialogs, they can also be used to change a dialog's background, header background or header icon in an animated manner. This is possible by using the
CrossFadeTransitionAnimation animation = new CrossFadeTransitionAnimation(this).setDuration(1000L).create();
CircleTransitionAnimation animation = new CircleTransitionAnimation(this).setX(0).setY(0).setRadius(0).setDuration(1000L).create();
ScaleTransitionAnimation animation = new ScaleTransitionAnimation.Builder(this).setDuration(1000L).create(); An example of a dialog, which uses a Contact informationFor personal feedback or questions feel free to contact me via the mail address, which is mentioned on my Github profile. If you have found any bugs or want to post a feature request please use the bugtracker to report them. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论