如何实现一个视图的Kotlin函数
我需要知道如何将函数实现到Kotlin中的ConstraintLayout。
我需要这样的东西:
fun applyCustomPropeties(){ //some stuff } val rootLayout = findViewById(R.id.rootLayout) rootLayout.applyCustomPropeties()
谢谢。
你可以添加一个扩展函数:
fun ConstraintLayout.applyCustomProperties() { //some stuff //you can use "this" keyword here }
这个扩展是“静态”解决的,所以不管你把代码放在哪里。 现在,你可以做你想做的事情:
val rootLayout = findViewById(R.id.rootLayout) rootLayout.applyCustomPropeties()
- Android录像机:未能获得表面
- 本地函数访问具有相同名称的父variables
- org.gradle.api.tasks.TaskExecutionException:执行失败的任务’:app:compileDebugKotlin’
- 为什么我的RxJava设置阻止我的UI线程? 使用BluetoothAdapter.startLeScan回调
- Android Studio中过时的Kotlin运行时警告
- Datepicker:如何在点击edittext时popupdatepicker
- 在kotlin中平台types的智能广播
- Kotlinx不能解决符号“合成”
- 如何在Kotlin中使用get()定义类的types属性