Search code examples
androidxmlxamarinlayoutxamarin.android

AutoSizeTextType uniform doesn`t work for custom text view in Xamarin.Android


I want to automatically scale font size depending on contents in Xamarin.Android app in custom class. Scaling works for TextView. But when I use NoobTextView scaling does not work.

Custom TextView Scales properly Does not scale


Solution

  • In the original TextView, the autosize attributes refer to the android: namespace. And in it, auto-size only works on the latest versions of the droid. Attributes from app: are only picked up by appcompat versions. Judging by the fact that now it works in this form - I have an AppCompat or Material theme installed, in which, during inflate, an AppCompatTextView or MaterialTextView is created instead of a TextView. Accordingly, no substitution occurs for custom TextViews. The solution is to inherit from AppCompatTextView.