How to prevent system font-size changing effects to a specific part of an Android application?

Viewed 2084

There is a system wide "Font size" setting allowing to resize text.

It generally works well, but there are cases where something special happens and specific part of view should ignore this setting and font size should remain at constant size.

I am aware about how to prevent system font-size changing effects to android application?

But accepted answer with dp is nowadays (Android 10) not working ( https://stackoverflow.com/a/21546897/4130619 )

https://stackoverflow.com/a/57225687/4130619 removes scaling in entire activity, https://stackoverflow.com/a/39346113/4130619 removes scaling in the entire app.

Affected code, with dp attempt already used (and failed):

            <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:id="@+id/compassNorth"
            android:layout_alignParentTop="true"
            android:text="@string/compass_north_one_letter"
            android:textColor="#000"
            android:textSize="10dp"/>

N (compass_north_one_letter) is changing size anyway:

enter image description here

2 Answers

Try autoSizeTextType, that make text size auto scale by available view size. https://developer.android.com/guide/topics/ui/look-and-feel/autosizing-textview

It allows you to specify max size, preset sizes so you could have more control. I don't know entire your layout so cannot test actually but from your snippet, for example,

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:id="@+id/compassNorth"
            android:layout_alignParentTop="true"
            android:text="@string/compass_north_one_letter"
            android:textColor="#000"
            app:autoSizeTextType="uniform"
        />

Also, I think you need to specify layout_height with specific size to limit view size for auto sizing. If it cannot work, please try app:autoSizeMaxTextSize, or granularly sizing as well.

In your case I would suggest using an image (dirty solution) because it's pretty straightforward in what you're trying to do. You could even create the image on the go but only if you need to go that deep.

Related