可见性不与Kotlin合作

ble*_*uel 12 android kotlin

嗨,下面给出的是我的代码,我的按钮应该变得不可见但是INVISIBLE不起作用

fun onPlay(view: View){
         var play = findViewById(R.id.play) as Button
         play.isClickable=false
         play.visibility=view.INVISIBLE
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*xTa 28

您的代码中有错误,可见性常量应该从Class变量设置,而不是从参数变量设置.通过View.INVISIBLE更改view.INVISIBLE

fun onPlay(view: View){
     var play = findViewById(R.id.play) as Button
     play.isClickable=false
     play.visibility= View.INVISIBLE // v letter should be capital
}
Run Code Online (Sandbox Code Playgroud)


小智 5

用于play.visibility=View.VISIBLE可见和play.visibility=View.GONE不可见或隐藏