ySgPjx
ySgPjx

Reputation: 10265

TextView autoSizeTextType not working in app widget

Can't get TextView text autosize to work in an app widget.

The autosize shows fine in Android Studio's preview, but it doesn't work on the actual widget.

Is autosize not supposed to work in widgets or something?

My TextView:

<TextView
        android:text="test"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/widget_text"
        android:gravity="center"
        android:background="?android:attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:textColor="#ddd"
        app:autoSizeTextType="uniform" 
        app:autoSizeMaxTextSize="200dp"
        app:autoSizeMinTextSize="12dp"/>

Upvotes: 1

Views: 1604

Answers (2)

Deˣ
Deˣ

Reputation: 4371

In the case of Widgets, the android:autoSizeTextType will work but the support will be from Android 8.0 only.

As app widgets are rendered by the home screen and the home screen might not know about the app namespace.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007554

Is autosize not supposed to work in widgets or something?

Your layout assumes that it is being inflated by something that understands those app-prefixed attributes. In the case of an app widget, that will not be the case. The system inflates the layout using a stock LayoutInflater, and it knows nothing about those attributes. The reason those attributes work in an AppCompatActivity is because it substitutes its own LayoutInflater which honors those app-prefixed attributes.

You are welcome to use android for those (e.g., android:autoSizeTextType). However, they will only be honored on Android 8.0 and higher, when auto-sizing was added to the framework.

If auto-sizing is critical for the operation of your app widget, you will need to set your minSdkVersion to 26.

Upvotes: 6

Related Questions