21582

Support libraries to add for Autosizing TextViews

Question:

I am confused about adding the correct support libraries in Android Studio to be able to use AutoSizing TextViews. <a href="https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview.html" rel="nofollow">https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview.html</a><br /> The description of what support libraries to use is kind of vague on this page. I have tried to import the suggested libraries, but either I am requesting the wrong libraries (they are not found, such as the android.support.v4.widget package) or I am doing something else incorrectly.

My min SDK is 21 and max SDK is 27, so the AutoSizing feature should be backwards compatible for my app if I have the correct libraries imported. However, in the screen design view, I get the warning "Attribute autoSizeTextType is only used in API level 26 and higher (current min is 21)"

As far as I can tell, I have the correct support libraries included. Project Structure Dependencies are as follows:

implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' implementation 'android.arch.lifecycle:compiler:1.0.0' implementation 'android.arch.persistence.room:runtime:1.0.0' implementation 'android.arch.persistence.room:compiler:1.0.0' implementation 'android.arch.paging:runtime:1.0.0-alpha4-1' implementation 'android.arch.core:core-testing:1.0.0' implementation 'android.arch.persistence.room:testing:1.0.0' implementation 'android.arch.lifecycle:common-java8:1.0.0' implementation 'com.android.support:support-v13:27.0.2' implementation 'com.android.support:appcompat-v7:27.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2-alpha1' implementation 'com.android.support:support-annotations:27.0.2' implementation 'com.android.support:support-v4:27.0.2' implementation 'com.android.support:preference-v14:27.0.2' implementation 'com.android.support:recyclerview-v7:27.0.2' implementation 'android.arch.lifecycle:extensions:1.1.0' implementation 'com.google.android.gms:play-services-location:11.8.0' implementation 'com.android.support:preference-v7:27.0.0' implementation 'com.android.support:support-compat:27.0.0'

Any suggestions? I also could use some links on how to convert the suggested libraries to the actual libraries to be imported. Thanks

Edit: partial list of layout with android:autoSizeTextType problem. I get the warning message for both of the textviews listed.

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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.support.constraint.Guideline android:id="@+id/guideline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_begin="134dp"/> <android.support.v7.widget.AppCompatTextView android:id="@+id/temperature_label" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:text="@string/temperature" android:autoSizeTextType="uniform" app:layout_constraintEnd_toStartOf="@+id/guideline" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> <TextView android:id="@+id/temperature" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:hint="@string/temperature" android:autoSizeTextType="uniform" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintLeft_toRightOf="@+id/guideline" app:layout_constraintTop_toTopOf="parent"/>

Edit: My Solution for now.

This layout is what I ended up with that seems to work for now. Not sure if the autoSizing is resizing or not, but this looks good on the devices I am testing for at this time. Tried the plain TextView using the app: prefix for autoSizeTextType as was suggested, but received the error "Unexpected namespace prefix "app" found for tag TextView". When I changed it to android.support.v7.widget.AppCompatTextView, the error went away. Thanks for the help.

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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.support.constraint.Guideline android:id="@+id/guideline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" app:layout_constraintGuide_percent="0.38"/> <android.support.v7.widget.AppCompatTextView android:id="@+id/temperature_label" android:layout_width="match_parent" android:layout_height="0dp" android:text="@string/temperature" android:textAppearance="@style/TextAppearance.AppCompat.Large" app:autoSizeTextType="uniform" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> <android.support.v7.widget.AppCompatTextView android:id="@+id/temperature" android:layout_width="match_parent" android:layout_height="0dp" android:hint="@string/temperature" android:textAppearance="@style/TextAppearance.AppCompat.Large" app:autoSizeTextType="uniform" app:layout_constraintLeft_toRightOf="@+id/guideline" app:layout_constraintTop_toTopOf="parent"/>

Answer1:

Change this:

<android.support.v7.widget.AppCompatTextView android:autoSizeTextType="uniform" .../>

to this:

<TextView app:autoSizeTextType="uniform" .../>

There's no need to reference AppCompatTextView directly. The LayoutInflater used by the support library will automatically inject AppCompat widgets in place of standard widgets.

Additionally, to get auto-sizing working pre-API-26, you need to be using the support library implementation, which means you need to be using the AppCompat attributes (with the app: namespace) instead of the platform attributes (with the android: namespace).

Answer2:

Autosizing is in support library. Use AppCompatTextView instead of regular TextView.

Answer3:

Try changing android: to app: namespace :

<android.support.v7.widget.AppCompatTextView app:autoSizeTextType="uniform" .../>

Recommend

  • Version conflict between google-services and android-gms
  • AndroidX : No instrumentation registered! Must run under a registering instrumentation
  • all com.android.support libraries must use the exact same version specification when adding google p
  • Cannot import com.google.android.gms:play-services-ads:17.1.1
  • exifinterface 27.1.0 , animated-vector-drawable:27.1.1 , All com.android.support libraries must use
  • Speed up for loop with numpy
  • NoSuchFieldError: RESOURCE_PREFIX with a maven project using tess4j
  • sendMail Function seem not working with Microsoft graph
  • How to format MonetaryAmount with currency symbol?
  • When does Spring creates proxies in the bean's lifecycle?
  • error while inflating class android.support.v7.widget.CardView
  • Spring: circular dependencies, @PostConstruct and order imposed by @DependsOn
  • SignalR An asynchronous operation error
  • CXF/Jetty equivalent of the following Jersey/Jetty code
  • What does 0x0 indicate in the instruction
  • Setup buildroot for old kernels
  • Can't run docker on os X with boot2docker
  • JMock- java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch()
  • What does a crossed out static import in Eclipse mean? [duplicate]
  • AdMob - Ad not displayed - Error 2
  • Import Protobuf generated classes using Gradle in IntelliJ
  • TagException … null (File not found) on creating custom Facelets tag [duplicate]
  • Android Get the markers that are not clustered
  • “cpanm PHP” fails
  • Get rendered html code in Backing Component from Composite Component
  • Unable to run tests with JUnit5 Console Launcher
  • How to create a new Bundle object?
  • Vuejs: Lifecycle hooks of child routerview components using keep alive
  • How to rotate the dial in a gauge chart? Using python plotly
  • npm 5.4.1 install/uninstall all failing
  • How to get current document uri in XSLT?
  • Bad request using file_get_contents for PUT request in PHP
  • Python urlparse: small issue
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string
  • costura.fody for a dll that references another dll