android kotlin - AlertDialog title text color size bold programmatically

MainActivity.kt

package com.cfsuman.kotlintutorials

import android.app.Activity
import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.text.SpannableString
import android.text.style.*
import android.widget.*
import com.google.android.material.dialog.MaterialAlertDialogBuilder


class MainActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val context:MainActivity = this

        // get the widgets reference from XML layout
        val button = findViewById<Button>(R.id.button)


        button.setOnClickListener {
            val builder = MaterialAlertDialogBuilder(context)

            val title = SpannableString("Lorem Ipsum")

            // alert dialog title text color
            title.setSpan(
                ForegroundColorSpan(Color.parseColor("#DA1884")),
                0,
                title.length,
                0
            )

            // alert dialog bold title
            title.setSpan(
                StyleSpan(Typeface.BOLD),
                0,
                title.length,
                0
            )

            // alert dialog title font
            title.setSpan(
                TypefaceSpan("sans-serif-light"),
                0,title.length,
                0
            )

            // alert dialog underline title
            title.setSpan(
                UnderlineSpan(),
                0,
                title.length,
                0
            )

            // alert dialog title text size
            title.setSpan(
                RelativeSizeSpan(1.2F),
                0,
                title.length,
                0
            )

            // dialog title
            builder.setTitle(title)


            // dialog message
            builder.setMessage(
                "Lorem ipsum dolor sit amet, consectetur adipiscing elit." +
                        " Integer ultricies ligula nec nibh ullamcorper," +
                        " ac porta tellus dignissim. Nam in posuere elit." +
                        " Sed suscipit nulla a egestas consequat."
            )

            // alert dialog buttons
            builder.setPositiveButton("OK",null)
            builder.setNegativeButton("No",null)
            builder.setNeutralButton("Cancel",null)

            // finally, create the alert dialog and show it
            val dialog = builder.create()
            dialog.show()
        }
    }
}
activity_main.xml

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#DCDCDC"
    android:padding="24dp">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Show Dialog"
        android:textAllCaps="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle dependencies[add]

// Material components
implementation 'com.google.android.material:material:1.6.1'
More android examples