2

I'm trying to implement the new textview autosize functionality on my app. I need to target API 21 then I read something about the backward compatibility using android.support.v4.widget.TextViewCompat but really I don't understand how to implement it.

    <android.support.v4.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:autoSizeMaxTextSize="100sp"
        android:autoSizeMinTextSize="8sp"
        android:autoSizeStepGranularity="2sp"
        android:autoSizeTextType="uniform"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

This code is completely wrong because the "Hello World!" text disappear.

Meanwhile this code:

    <android.support.v7.widget.AppCompatTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:autoSizeMaxTextSize="100sp"
        android:autoSizeMinTextSize="8sp"
        android:autoSizeStepGranularity="2sp"
        android:autoSizeTextType="uniform"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

...appears to be good but the editor continue to warning about the minimum API level of 26...

Here my Gradle implementations:

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-core-utils:28.0.0'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'com.android.support:support-v4:28.0.0'

Edit: While I'm trying to working on android.support.v7.widget.AppCompatTextView I found another issue (Java):

TextViewCompat textViewCompact;
textViewCompact = findViewById(R.id.TextView1);

This last line is marked as error: "Type parameter T has incompatible upper bounds: View and TextViewCompact" I'm starting to think to continue to use TextView and autosize it by:

TextView textView = findViewById(R.id.TextView1);
TextViewCompat.setAutoSizeTextTypeWithDefaults(textView, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);

Is this the right way to use it?

MD Naseem Ashraf
  • 1,030
  • 2
  • 9
  • 22
  • Please don't tag questions with IDE tags (android-studio) just because you use that IDE: these tags should only be used when you have questions about the IDE itself, & not any code you write (or want to write) in it. See [when is it appropriate to remove an IDE tag](https://meta.stackoverflow.com/a/315196/6296561), [How do I avoid misusing tags?](https://meta.stackoverflow.com/questions/354427/how-do-i-avoid-misusing-tags), & [tagging guide](https://stackoverflow.com/help/tagging). Also, please read [How to Ask](https://stackoverflow.com/help/how-to-ask) & use android tag on android questions. – MD Naseem Ashraf Apr 09 '19 at 04:30

1 Answers1

0

in xml

<android.support.v7.widget.AppCompatTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:autoSizeMaxTextSize="100sp"
    app:autoSizeMinTextSize="8sp"
    app:autoSizeStepGranularity="2sp"
    app:autoSizeTextType="uniform"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

in java

    AppCompatTextView textView = findViewById(R.id.text);
    TextViewCompat.setAutoSizeTextTypeWithDefaults(textView, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
fancyyou
  • 965
  • 6
  • 7