请参阅下面的代码 apply_job 值可能是 true 或 false
<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
关于kotlin - 基于真假值我应该如何仅使用 kotline 在 xml 文件中使按钮的可见性为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49232887/