Building a Alert Widget


Minimum SDK version


This is a guide on building a custom Alert Widget. For an overview of the Custom Widget UI system see Custom Widget UI.

Alert Widget Model

Alert Widget Data
The Alert Widget Model provides data about the Alert Widget such as the title text, content text, a url to an image and more.

API Reference

The model also provides metadata about the widget such as the Date that it was created or the timeout duration set by the Producer.

class CustomAlertWidget : ConstraintLayout{

    lateinit var alertModel: AlertWidgetModel

    constructor(context: Context) : super(context) {
        init(null, 0)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        init(attrs, 0)

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
    ) {
        init(attrs, defStyle)

    private fun init(attrs: AttributeSet?, defStyle: Int) {
        inflate(context, R.layout.custom_alert_widget, this)

    override fun onAttachedToWindow() {
        bodyText.text = alertModel.widgetData.title
        alertModel.widgetData.imageUrl?.let {