반응형
구글 공식 레퍼런스 문서 확인!
https://developer.android.com/reference/com/google/android/material/textfield/TextInputEditText
1. TextInputEditText를 사용하기 위해서는 gradle(module)에 material이 추가되있어야한다.
implementation 'com.google.android.material:material:1.6.0'
2. xml에 다음과 같이 추가한다.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/form_username">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
3. 기본 FilledBox 테마가 적용된 TextInputEditText 완성
두가지 스타일과 기타 옵션으로 이것저것 추가가 가능하다
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.home.HomeFragment">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="이름"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="비밀번호"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="생일"
app:boxBackgroundColor="@color/md_yellow_50"
app:counterEnabled="true"
app:counterMaxLength="20"
app:hintTextColor="@color/white"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
반응형
'Android' 카테고리의 다른 글
EditTextView에서 자동으로 폰번호 - 넣기 (0) | 2022.05.13 |
---|---|
Bitbucket에서 갑자기 Git pull push 안될때 !!! (0) | 2022.05.13 |
ConstraintLayout 버튼 Front 적용이 안될때 | bringtoFront 안될때 (0) | 2022.05.13 |
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. Error (0) | 2022.05.13 |
Android CircleProgressBar 라이브러리 (0) | 2022.04.12 |
댓글