Android how to retain the same textView height even after text size changes?

229 views Asked by At

I noticed in my app that some of my AutoCompleteTextViews height are being increased whice cause my UI to look weird if the user changes the device text size in the settings.. ive looked into autoSizeTextType and set it to none but it does not solve it and I also use dp as the textsize instead of sp which causes the text to stay in the same size but the view itself get increased height which breaks my UI..

Any suggestions on how to keep the view height fixed and avoid the change caused by device text size changes?

*I half-solved it only when setting the height to explicit dp size e.g 25dp but then text I type inside is not fitting the view and you cant see whats written insde..

my AutoCompleteTextView xml:

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/contactNameTextField"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginTop="5dp"
            android:layout_marginEnd="10dp"
            android:textColorHint="@color/hintColor"
            android:theme="@style/EditTextStyle"
            app:boxBackgroundColor="@color/fragmentBackground"
            app:boxStrokeWidth="3dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@id/nameText"
            app:layout_constraintTop_toTopOf="@id/nameText">

            <AutoCompleteTextView
                android:id="@+id/itemContactName"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:autoSizeTextType="none"
                android:imeOptions="actionDone"
                android:maxLines="1"
                android:textSize="18dp" />

when increasing the text size in device settings

1

There are 1 answers

0
Spyware On

You can do it by typing <item name="android:textSize">textsize<item/> in your styles.xml or themes.xml. Note that it will change the whole text size of the application. Or if it doesn't work, see this answer. I am sure it will help you.