Material-components-android: [TextInputLayout] Invisible box outline on empty text and Suffix ruining box

Created on 22 Nov 2020  路  3Comments  路  Source: material-components/material-components-android

Description: Box outline doesn't appear when focused with empty text :
Unfocused
Screenshot 2020-11-22 113239
Focused
Screenshot 2020-11-22 113326
Focus with text
Screenshot 2020-11-22 115504
Also in errors
Screenshot 2020-11-22 113452

Another issue is that suffixes and trailing icons overlap the stroke:
Screenshot 2020-11-22 113503
And my calendar's trailing icon disappears on error even though it's still clickable
Screenshot 2020-11-22 115121

Expected behavior: For the outline to appear even with empty text and errors. And my trailing icon to still be visible on error.

Source code: A snippet of one of my fields:

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/add_diameter_lay"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginTop="16dp"
                android:hint="@string/tree_diameter"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@id/add_height_lay"
                app:suffixText="@string/meter">
                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/add_diameter"
                    android:textAlignment="center"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="numberDecimal"
                    android:textSize="14sp"
                    android:imeOptions="actionDone"/>
            </com.google.android.material.textfield.TextInputLayout>

Android API version: API 29

Material Library version: 'com.google.android.material:material:1.2.1'

Device: Pixel 2 api 30 emulator and my HTC 10 android 8.0

bug

Most helpful comment

@Doomski99 I had the same issue and fixed it with the help of this answer: https://stackoverflow.com/questions/64596156/boxstroke-with-material-outline-box-doesn%C2%B4t-work

Basically, you should check if you're setting "android:background" in your main style, because the OutlineBox will use that value for the container border. And because the Activity background is the same color, you can't see anything.

All 3 comments

could you provide a sample app that reproduces the issue?

@Doomski99 I had the same issue and fixed it with the help of this answer: https://stackoverflow.com/questions/64596156/boxstroke-with-material-outline-box-doesn%C2%B4t-work

Basically, you should check if you're setting "android:background" in your main style, because the OutlineBox will use that value for the container border. And because the Activity background is the same color, you can't see anything.

THANK YOU SO MUCH! @LukaKit
All is fixed !!

Was this page helpful?
0 / 5 - 0 ratings