Search code examples
kotlinnoty

emre1512 Noty RelativeLayout creation in Kotlin


I have a simple MainActivity with a simple main layout like this:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        ... />
</androidx.constraintlayout.widget.ConstraintLayout>

I need to activate Noty on this activity. What I need to know is how to create RelativeLayout "yourLayout" in its simple exmple in Kotlin.

Noty.init(YourActivity.this, "Your warning message", yourLayout, Noty.WarningStyle.SIMPLE).show();

Thank you!


Solution

  • Add an android:id attribute to your ConstraintLayout tag:

    android:id="@+id/root"
    

    Now you can fetch a reference to that ConstraintLayout in code:

    val root: ConstraintLayout = findViewById(R.id.root)
    Noty.init(this@MainActivity, "Your warning message", root, Noty.WarningStyle.SIMPLE).show()