请参阅下面的代码 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