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?