-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TextInputLayout] Prefix not aligned correctly when phone font size is changed #773
Comments
Could you provide screenshots and the source code? |
I realized that only the last 2 small sizes of the phone font only affect this bug Screenshot Source Code <com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginPhoneInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/phone_number"
app:boxStrokeColor="@color/mtrl_textinput_default_box_stroke_color"
app:hintTextColor="?attr/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:prefixText="+1"
app:prefixTextColor="@color/textPrimaryColor"
app:startIconDrawable="@drawable/ic_phone_android_white_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/phoneNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/transparent"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="phone" />
</com.google.android.material.textfield.TextInputLayout> |
@Edydaoud
or set style look like this and set prefix text size
|
It's also unaligned on my end. Even when setting <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/mobile_number_hint"
app:boxBackgroundColor="@color/colorSurface"
app:boxStrokeColor="@color/colorOnSurface"
app:hintTextColor="@color/colorOnSurface"
app:prefixText="+1"
app:prefixTextAppearance="@style/TextAppearance.App.Body1">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLength="14"/>
</com.google.android.material.textfield.TextInputLayout> Anything else we can do about this? |
I also get this bug, the height is sometime automatically resized. And I fix it by adding height value.
|
I used |
Tried adding the height value, I am still having the issue. |
While the following solution is hacky as well, it works better than modifying the sizes. I'm adding this after the view is initialized.
|
@anishbajpai014 has a good solution! |
While we are waiting for the fix to be released, @anishbajpai014's solution looks the best so far; but with a little tweak so that it looks safer and cleaner.
|
@mrehan27 your solution is good too, but requires android core ktx. It's not a problem, just a warning. |
Tried both @mrehan27 and @anishbajpai014 's methods and it still cannot stay in the center of the text view. If I use the following code, the prefix text will look like right/end aligned.
Prefix style is like this:
If I use a specific height/width dp value in
|
For me changing gravity to Gravity.BOTTOM solved the case:
|
This solution worked for me after wasted some hours |
Description: The prefix horizontal alignment is not correct when the font size of the phone is changed, it seems to be a bit higher from the text inside the TextInputEditText
Expected behavior: Should be aligned correctly the TextInputEditText
Android API version: Android 10
Material Library version: 1.2.0-alpha01
Device: Samsung Galaxy s10
The text was updated successfully, but these errors were encountered: