基于真值和假值,我应该如何使用 Kotline 在 XML 文件中使按钮 true 可见



请参阅下面的代码 apply_job值可能是真或假

<Button
            android:id="@+id/apply_job"
            android:layout_width="match_parent"
            android:text="Apply"
            android:background="@color/colorPrimary"
            android:layout_height="wrap_content" />

在 Kotlin 中,如果您使用 kotlin 扩展,则不必初始化变量。

确保已将此插件添加到模块的 build.gradle

apply plugin: 'kotlin-android-extensions'

管理可见性

val canShow = true
apply_job.visibility = if(canShow) View.VISIBLE else View.GONE

最新更新