Kotlin and Android Development featuring Jetpack: android:tint vs app:tint (chapter 7, p186)

I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint.

How to replicate:

  1. load chapter-7 from zipfile into Android Studio

  2. view layout_coin_slot.xml

  3. Notice that Android Studio is complaining about android:tint="@color/coin_slot_color" in the coin slot’s ImageView

Changing it to app:tint="@color/coin_slot_color" fixes it.

The code in the zipfile is consistent with the code in the text… but both are actually wrong (at least, as far as ArcticFox in October 2021 is concerned) and the prefix has to be changed in order to successfully compile.

I think adding the dependency on com.google.android.material on p179 is what caused the use of android:tint to break in chapter 7 (because it worked just fine in chapter 6). I’m not 100% sure, but it looks like Google’s original implementation of the Material library had a bug, and they later decided to fix it in a way that caused any code that used the original syntax (with the ‘android’ prefix) to break.

Due to the namespace change for app:tint, the section about changing the other two Views becomes confusing.

The ImageView needs app:tint="@color/coin_slot_color", but the View needs android:backgroundTint="@color/coin_slot_color", and the TextView needs android:textColor="@color/coin_slot_color"