2

I need to use autosizing in TextView below API 26, so I read this: https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview

The library provides support to Android 4.0 (API level 14) and higher. The android.support.v4.widget package contains the TextViewCompat class to access features in a backward-compatible fashion.

So, I'm adding this in gradle:

implementation 'com.android.support:support-v4:28.0.0'

But now, how to use TextViewCompat in xml file? I can't find any info about that in the documentation or statckoverflow. I can see other persons using android.support.v7.widget.AppCompatTextView but that TextView depends on support-v7 extra gradle library and it's not the TextViewCompat the documentation is talking about.

How to use TextViewCompat for autosizing below api 26?

NullPointerException
  • 36,107
  • 79
  • 222
  • 382

2 Answers2

2

TextViewCompat is part of the 'old' support library which is now deprecated. The androidx libraries are 'better/newer/what we should be using' - here is the overview: AndroidX Overview

The AppCompatTextView control is an AndroidX text view with all the shiny new features you want that works with older versions of Android - you can find the documentation here:

AppCompatTextView AndroidX documentation

Confusingly there is also an AppCompatTextView in the v7 support library and the documentation for that is still showing higher in the Google search (at least for me). If you look at the webpages for v7 docs they do all say DEPRECATED in the background.

As a general rule you basically need to know that anything that is documented as existing in a support library should now be sourced through AndroidX. There are lots of places where this isn't obvious though (like almost everywhere)

leafcutter
  • 747
  • 7
  • 14
-1

This Library will work for you.

https://github.com/grantland/android-autofittextview

hope to be useful.

majid ghafouri
  • 787
  • 2
  • 7
  • 23