2 Android components you should start using right now!

1. Content Loading ProgressBar

Loading indicators on Android are easy to use thanks to ProgressBar. It comes with a large variety of styles; circles, bars, with or without progress, small or large. They are adapted to many use case and therefore used widely in any Android Apps.

2. Material Design Dialog Builder

Dialogs have been in computing system for ages and yet there is still a little to learn. I’ve recently realised that many developers still use AlertDialog class provided by Android, and there is nothing bad with that, but I believe the MaterialAlertDialogBuilder has something to offer and people should know about it.

AlertDialog.Builder(context)
.setTitle("Dark Theme is here!")
.setMessage("Android Developer News now supports Dark Theme!")
.setPositiveButton("👍 Thanks!") { dialog, _ ->
dialog.dismiss()
}
.show()
MaterialAlertDialogBuilder(context)
.setTitle("Dark Theme is here!")
.setMessage("Android Developer News now supports Dark Theme!")
.setPositiveButton("👍 Thanks!") { dialog, _ ->
dialog.dismiss()
}
// Add customization options here
.show()

Let’s compare the dialogs

On the left: Android AlertDialog.Builder, on the right: MaterialAlertDialogBuilder

Customising the Dialogs and Overlay: Style it up! 🎨

Because of Material Design, it is possible to customise the dialog in many ways, using styles. This include having the cut shape or choosing the overlay opacity.

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">    
...
<item name="materialAlertDialogTheme">@style/DialogTheme</item>
...
</style>

<style name="DialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="alertDialogStyle">@style/DialogStyle</item>
<item name="android:backgroundDimAmount">0.70</item>
</style>

<style name="DialogStyle" parent="MaterialAlertDialog.MaterialComponents">
<item name="shapeAppearance">@style/CutShape</item>
</style>

<style name="CutShape" parent="ShapeAppearance.MaterialComponents.MediumComponent">
<item name="cornerFamily">cut</item>
<item name="cornerSize">8dp</item>
</style>
Using cut corners on Android Developer News Light and Dark version

Many more Material Components

Google is releasing new components for Android on a regular basis. Using them will ensure you to get the latest features and customisations in the future.

Conclusion

We have seen that with just a few lines of code, you can bring a better User Experience to your audience. It worth to explore a little bit and find out about the more sophisticated yet available out-of-the-box components.

Android Developer News

If you read this far, you might want to know about the App I’m currently building: Android Developer News. Its purpose is to bring the latest trends about Android Development in the palm of your hand. Famous library updates, interesting podcasts and blog articles, Android Studio releases and even codelabs. You can download it from the Play Store just here.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store