简体   繁体   English

Kotlin:未解决的参考:alpha

[英]Kotlin : Unresolved reference: alpha

I don't understand why, on a project that use Java and Kotlin, in Kotlin I have issues calling some methods of the View class. I don't understand why, on a project that use Java and Kotlin, in Kotlin I have issues calling some methods of the View class.

If I try to modify the alpha of my AppCompatButton如果我尝试修改 AppCompatButton 的 alpha

binding.button.alpha = 0.5F

of if I directly try to modify the alpha on a newly created View如果我直接尝试在新创建的视图上修改 alpha

val view = View(context)
view.alpha = 1F

I have the following error我有以下错误

Execution failed for task ':app:compileAllDebugKotlin'.任务 ':app:compileAllDebugKotlin' 执行失败。 Unresolved reference: alpha未解决的参考:alpha

Some methods of the View class works some don't. View class 的某些方法有效,有些则无效。

That's very strange, because View class has the alpha property and it should work.这很奇怪,因为View class 具有alpha属性,它应该可以工作。

Make sure that you have API level >= 11 and that you have a correct imports:确保您的API 级别>= 11 并且您有正确的导入:

import android.view.View

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM