iOS-style dialogs have a sleek and polished look that many users find appealing. If you're developing an Android app but want to incorporate the aesthetics of iOS dialogs, here's a step-by-step guide on how to implement iOS-style dialogs in your Android project.

 Library Credit: iOS UIAlertView on Android. (github.com)

Step 1: Add the Dialog Library to Your Project

The first step is to include the iOS-style dialog library in your Android project.

1.1 Add the Dependency

To use the dialog library, add the following dependency to your build.gradle file inside the dependencies section:

__________________

dependencies { implementation 'com.github.gdacciaro:iosdialog:1.0.5' }

or use AAR file if you have not found this library 

AAR file link click me

dependencies {     implementation files('libs/iosdialog-1.0.3.aar')  }

On AndroidProject 

Create a "libs" folder then Add that AAR file

__________________

1.2 Add JitPack Repository

Since this library is hosted on JitPack, make sure to add the JitPack repository to your project-level build.gradle file:

_________________

allprojects { repositories { google() mavenCentral() maven { url 'https://jitpack.io' } } }
_______________



Step 2: Sync Your Project After adding the dependencies, click on "Sync Now" in Android Studio to sync
your project with the changes. This will download the necessary files for the dialog library.
Step 3: Use the Dialog in Your Code Once the library is added, you can start using the dialog in your Android activities or fragments. 3.1 Basic Usage Here's how you can create a simple iOS-style alert dialog in your Android app:


Here's how you can create a simple iOS-style alert dialog in your Android app:


import com.gdacciaro.iOSDialog.iOSDialog import com.gdacciaro.iOSDialog.iOSDialogBuilder // Inside your activity or fragment iOSDialogBuilder(this) .setTitle("Alert Title") .setSubtitle("This is an iOS-style dialog on Android") .setCancelable(false) .setPositiveListener("OK") { dialog -> // Handle the positive button click dialog.dismiss() } .setNegativeListener("Cancel") { dialog -> // Handle the negative button click dialog.dismiss() } .build() .show()


3.2 Customizing the Dialog

The dialog library allows for customization, including title, subtitle, button text, and more.

Here’s an example of how you can customize it further:

iOSDialogBuilder(this) .setTitle("Warning!") .setSubtitle("Are you sure you want to delete this item?") .setBoldPositiveLabel(true) .setCancelable(true) .setPositiveListener("Delete") { dialog -> // Action when the positive button is clicked deleteItem() dialog.dismiss() } .setNegativeListener("Cancel") { dialog -> dialog.dismiss() } .build() .show()


Step 4: Run the App

Once you've added the dialog and customized it as per your needs, run your Android app, and you should see an iOS-style dialog displayed when the dialog code is triggered.

Additional Features

  • Cancelable Dialogs: You can control whether the dialog is cancelable by the user.
  • Custom Button Labels: You can set custom text for positive and negative buttons.
  • iOS Look and Feel: The dialog mimics the iOS UI style, enhancing the user experience for those who prefer iOS aesthetics.

Conclusion

By following these steps, you can implement iOS-style dialogs in your Android app. It's an effective way to

provide a sleek and modern dialog interface to enhance the overall user experience. Happy coding!