简体   繁体   中英

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!

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM