Android Basic Alert Dialog Box

Alert tutorial.

Android Basic Alert Dialog Box

First, your XML layout should include an id for the ConstraintLayout. This is usually the parent (or root) tag on your layout.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

</androidx.constraintlayout.widget.ConstraintLayout>

The critical part is the android:id="@+id/mainLayout". Don't forget it. It has an id of mainLayout.

Next, we need to write some Kotlin code. It's not too difficult, just type this:

        Snackbar.make(mainLayout, "Updated 3h ago", Snackbar.LENGTH_INDEFINITE).show()

More Tutorials

Android Basic Alert Dialog Box
Basic CardView

Basic CardView

Material Design.

Rounded Corners with a Border
Rounded Button in Android Studio

Rounded Button in Android Studio

Create beautiful buttons in XML.

RecyclerView Day 3: Invoicing app

RecyclerView Day 3: Invoicing app

Built with Android Studio and Kotlin.

Build a Ridesharing Android App - Part 1

Build a Ridesharing Android App - Part 1

Getting started is sometimes the hardest part.

setOnClickListener

Add a click listener in Kotlin.

Android Login Layout

Let users sign in.

Registration Screen

Registration Screen

It always begins with registration.