October 2019
Intermediate to advanced
434 pages
11h 54m
English
Once the experimental features are turned on, we can reference synthetic view bindings to access our views. This means that the Android Extensions plugin will generate view bindings for us. In MainActivity, we can add the following import to reference the Button defined in our activity_main.xml file:
import kotlinx.android.synthetic.main.activity_main.button
Once we've included the import, we can reference that view directly without any call to findViewById() or another variable declaration:
button.apply { text = "Hello Kotlin" gravity = Gravity.START setTextColor(resources.getColor(R.color.colorAccent))}
By default, the view will be named after the android:id attribute in the XML. In this case, ...
Read now
Unlock full access