textAppearance does not work on custom TextView

Having a custom TextView is a totally normal thing these days. The problem comes when you try the following:

    android:textAppearance="@style/MyCustomTextAppearance" />

If your custom TextView extends from the TextView class then this textAppearance that you have set will probably not work. It works in the Preview but it is never displayed correctly on the emulator or on a real device.

The fix is very simple. Just extend from AppCompatTextView. And now everything works!

The AppCompat documentation says it alone:

This will automatically be used when you use TextView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

You may also like...