Manukumar Manukumar - 29 days ago 8
Android Question

TextView autoSizeTextType is not detecting in xml

I'm looking for changing the TextView Sizes automatically. And I found the solution as well. Here is the official Doc for Auto sizing textviews. But Still I'm not able to resolve it. When i paste autoSizeTextType its showing error in xml file.

Here is the my xml code and gradle code snippets

myactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">

<include layout="@layout/toolbar" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:autoSizeTextType="uniform"/>


</LinearLayout>


Gradle snippet

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:support-v4:25.2.0'//Added support library
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
testCompile 'junit:junit:4.12'
}

Answer Source

As stated in the docs:

The Support Library 26.0 Beta provides full support to the autosizing TextView feature on devices running Android versions prior to Android O. The library provides support to Android 4.0 (API level 14) and higher

You need to upgrade your support lib to v26.0.0-beta2 in order to use that feature.

compile 'com.android.support:support-v4:26.0.0-beta2'

Don't forget to upgrade your buildToolsVersion to 26.0.0 and compileSdkVersion to 26 as well.