emre1512 在 Kotlin 中创建 Noty RelativeLayout

Posted

技术标签:

【中文标题】emre1512 在 Kotlin 中创建 Noty RelativeLayout【英文标题】:emre1512 Noty RelativeLayout creation in Kotlin 【发布时间】:2020-11-14 16:24:16 【问题描述】:

我有一个简单的 MainActivity,主布局如下:

<?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_
    android:layout_>

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

我需要在此活动上激活Noty。我需要知道的是如何在 Kotlin 的简单示例中创建 RelativeLayout “yourLayout”。

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

谢谢!

【问题讨论】:

【参考方案1】:

android:id 属性添加到您的ConstraintLayout 标签:

android:id="@+id/root"

现在您可以在代码中获取对 ConstraintLayout 的引用:

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

【讨论】:

以上是关于emre1512 在 Kotlin 中创建 Noty RelativeLayout的主要内容,如果未能解决你的问题,请参考以下文章