Android Kotlin開發之使用Butterknife註意要點
阿新 • • 發佈:2018-07-24
nproc img init () 進行 不知道 cep ini nbsp
使用kotlin-kapt插件
依賴由java的annotationProcessor改為kapt
在使用控件綁定使用時,網上搜使用方法,不知道被哪個家夥帶坑裏了。
//錯誤用法
@BindView(R.id.tv_title)
lateinit var tvTitle :TextView
導致使用控件時,根本沒有綁定成功,報錯
kotlin.UninitializedPropertyAccessException: lateinit property title has not been initialized
//正確使用
tv_title.setTextColor(Color.RED)tv_title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17F)
tv_title.text = "大標題"
Kotlin使用Butterknife控件綁定註解,不需要@BindView了
只要在activity或fragment...中進行Butterknife.bind()之後,直接用布局的id使用就好了
Android Kotlin開發之使用Butterknife註意要點