TextInputLayout

나고수·2022년 3월 19일
0

1일1공부

목록 보기
21/67

공식문서
참고블로그

<com.google.android.material.textfield.TextInputLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:hint="@string/form_username">

     <!--TextInputLayout의 자식으로 그냥 EditText를 써도 되지만, custom이 100% 안될 수도 있다고 한다.-->
     <!--힌트는 EditText가 아닌 TextInputLayout에 써야한다고 한다.-->
  <!--layout_height 는 둘다 wrap_content 로 해주세요. 텍스트 사이즈에 맞게 조정됩니다. 임의 설정시 잘못 조절하면 TextinputLayout 의 힌트 라벨과 TextInputEditText 의 텍스트가 겹치게 나올 수 있습니다.-->
  <com.google.android.material.textfield.TextInputEditText
             android:layout_width="match_parent"
             android:layout_height="wrap_content"/>

 </com.google.android.material.textfield.TextInputLayout>
//.kt
 //힌트를 볼드로 넣고 싶어서 kotlin file에 넣었음
val boldHint = HtmlCompat.fromHtml( "<b>phoneNumber</b>", HtmlCompat.FROM_HTML_MODE_LEGACY)
binding.textInputLayout.hint = boldHint
// app의 theme이 > Theme.MaterialComponents < 로 되어 있어야한다. 
                                             
  <style name="MyInputTextLayoutFloatingTextAppearanceStyle" parent="TextAppearance.AppCompat">
        <item name="android:textSize">30sp</item>
    </style>


    <style name="MyInputTextLayoutStyle" parent="Widget.Design.TextInputLayout"> // important : parent 를 이것으로.
    <item name="colorControlNormal">@color/yellow</item>  // unFocus 상태일때 밑줄 색.
    <item name="colorControlActivated">@color/red</item> // Focus 상태일때 밑줄 색.
    <item name="android:textCursorDrawable">@color/red</item>  // cursor 색.
    <item name="hintTextAppearance">@style/MyInputTextLayoutFloatingTextAppearanceStyle</item> //floating hint text 스타일
    <item name="android:textColorHint">@color/navy</item>  // hint 색
    <item name="hintTextColor">@color/green</item>   // floating hint 색
    <item name="android:textSize">50sp</item>   // textSize를 설정하면 textInputLayout과 editText의 글자 크기가 모두 바뀝니다. 
      //InputTextLayout은 hint만 있고 text 속성은 없는듯. 
      //InputTextLayout에서 text 속성을 주면 edittext 속성이 바뀌는 것 같습니다.
    </style>
<!--TextInputLayout의 theme과 style을 모두 custom Theme으로 바꿔줘야합니다!-->   
 <com.google.android.material.textfield.TextInputLayout     
       style="@style/MyInputTextLayoutStyle"
        android:theme="@style/MyInputTextLayoutStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textInputLayout">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/textInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </com.google.android.material.textfield.TextInputLayout>
  • inputTextLayout의 그냥 hint와 floating hint 일 때 textSize는 다르게 할 수 있지만, font는 다르게 할 수 없는 것 같다. 못찾았음..
  • inputTextLayout 의 floating hint, 그냥 hint / eidtText의 글자 크기를 각각 다르게 하는 법? >> 🤷‍♀️
  • inputTextLayout 의 floating hint, 그냥 hint / eidtText의 글자 색상을 각각 다르게 하는 법 ⤵️
style에서 지정 
<item name="android:textColorHint">@color/navy</item>  // hint 색
<item name="hintTextColor">@color/green</item>   // floating hint 색
layout 에서 지정 
   //editText 색 && background에 null을 주면 밑줄 빠짐 
   <com.google.android.material.textfield.TextInputEditText
            android:textColor="@color/purple_200" 
            android:background="@null"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
profile
되고싶다

0개의 댓글