위와 같은 검색창을 만들 때 아래와 같은 조합을 사용하였습니다.

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/layout_et_search"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginHorizontal="24dp"
            android:layout_marginVertical="6dp"
            app:boxStrokeWidth="0dp"
            app:boxStrokeWidthFocused="0dp"
            app:hintEnabled="false"
            android:gravity="center_vertical"
            app:layout_constraintBottom_toTopOf="@+id/layout_friend_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:startIconDrawable="@drawable/ic_bottom_search">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/et_search"
                style="@style/Widget.TextView.Noto12_Gray2_Medium.Style"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textColor="@color/on_surface"
                android:textColorHint="@color/grey_2"
                android:hint="@string/nickname_search"
                android:gravity="center_vertical"
                android:background="@drawable/shape_rectangle_grey_1_16dp"
                app:hintTextColor="@color/grey_2" />

        </com.google.android.material.textfield.TextInputLayout>

그런데 지금 검색창은 제가 TextInputEditText에 적용한 hint속성도 보이지 않고,

타이핑을 해도 TextInputEditText에는 글씨가 보이지 않는다.

 

실제 기기에서 사용할때도 타이핑한 글씨가 보이지 않습니다.


현재 TextInputLayout이 조금 작은 상태인데 크기를 조금 늘려보면

기존 35dp에서 110dp로 height를 조정한 상태

다음과 같이 TextInputEditText의 hint가 약간 하단에 위치하고 있습니다. 기본적으로 TextInputLayout에는 hintLabel이 존재하고 이때문에 Label만큼의 크기가 확보되지 않으면 위 처럼 실제 타이핑하는 글씨와 hint text가 보이지 않는 것입니다.

 

따라서 TextInputEditText에 아래 속성을 추가해 줍니다. 

android:paddingVertical="0dp"

 

paddingVertical = 0을 적용한 상태

크기를 다시 작제 조정했음에도 처음과는 다르게 hintText까지 잘  보이게 되었습니다

paddingVertical = 0을 적용한 상태 (110dp->35dp)

 

타이핑 한 결과도 잘 적용되었습니다.

 

결론

TextInputEditText에 아래 속성을 적용해보자!

android:paddingVertical="0dp"

 

+ Recent posts