Log.v(“ThreeTips”, ”#15”)

1 — Mutate your drawable!

val drawable = ContextCompat.getDrawable(context, R.drawable.icon)
drawable.setColorFilter(Color.WHITE)

Everything seems OK. Until you need to use same resource in different page.I want to share official documentation about Drawable.

All drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification.

So If you load R.drawable.icon in another activity you will see latest modification which is applied previous activity.
There is a method in Drawable class to prevent this, mutate().

This method makes drawable mutable and this operation can not be reversed. A mutable drawable is guaranteed to not share its state with any other drawable.

ContextCompat.getDrawable(context, R.drawable.icon).mutate()

2 — Databinding meets Kotlin

dataBinding {
enabled true
}

In kotlin, you also need to add databinding processor to your build.gradle.

//version must be the same than our gradle version
kapt 'com.android.databinding:compiler:3.0.0'

3 — Be aware of style trick

<style name="BigButton"/>

<style name="BigButton.Awesome"/>

<style name="BigButton.Great" parent="SmallButton"/>

What is the parent of BigButton.Great style? BigButton or SmallButton ? or both?
The answer is SmallButton.

If you declare style, you can define its parent in two ways. One of them is defining them with dot notation. Just like in the “BigButton.Awesome” style. Another way is define them with “parent” attribute. But when you combine them both, parent attribute takes precedence. So don’t mix both parenting rules. It leads to confusion about styles. When using “BigButton.Great” in your xml, developer thinks that it is BigButton but when he digs into style, realises that it is Small. So It leads to an illusion, don’t mix parenting!

Software Engineer at Storytel