TextInputEditText
๊ธฐ๋ณธ edittext์ ๋ค๋ฅด๊ฒ ๋ ๋ค์ํ ๊ธฐ๋ฅ์ ์ง์ํ๋ edit text์ ํ ์ข ๋ฅ์ด๋ค.
TextInputEditText์๋ ๊ฐ๋ ค์ผ ํ ํ ์คํธ(๋น๋ฐ๋ฒํธ)๊ฐ ์๋ ๊ฒฝ์ฐ passwordToggleEnabled๋ผ๋ ์ต์ ์ ์ฌ์ฉํ ์ ์๋ค.
ํ์ง๋ง passwordToggleEnabled ์ ์ฌ์ฉํ๋ค ๋ณด๋ฉด ์ด์ํ ๋ฌธ์ ๋ฅผ ๋ง๋ ์ ์๋๋ฐ
๋ฐ๋ก ๋น๋ฐ๋ฒํธ๋ ๋ณด์ด์ง๋ง ์์ด์ฝ์ ๋์ ๊ฐ๋ฆฌ๊ณ (?) ์๊ฒ ๋จ๋ ๋ฌธ์ !
์ด๋ฒ์๋ ์ด ๋ฌธ์ ๋ฅผ ๋ด๊ฐ ํด๊ฒฐํ ๋ฐฉ๋ฒ์ ๋ํด ํฌ์คํ ์ ํ๊ฒ ๋ค.
๋จผ์ toggle icon์ด ํด๋ฆญ๋์์ ๋ ๋์ค๊ฒ ํ๋ ์์ด์ฝ๋ค์ ์ค์ ํ๋ค.
toogle_icon_status.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/baseline_remove_red_eye_black" android:state_checked="true"/>
<item android:drawable="@drawable/baseline_visibility_off_black"/>
</selector>
ํด๋ฆญ๋์๊ฑฐ๋ ์๋ ๋์ ์์ด์ฝ์ ์๋ฌด๊ฑฐ๋ ์ ํด๋ ์๊ด์๋ค.
ํ์ฌ edittext๊ฐ ์๋ xml ํ์ผ์ ์ ์ฉํด์ค๋ค.
activiy_login.xml(editText ๋ถ๋ถ)
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/pw_input_layout"
. . .
app:passwordToggleEnabled="true"
app:passwordToggleTint="@null"
app:passwordToggleDrawable="@drawable/toggle_icon_status">
<com.google.android.material.textfield.TextInputEditText
. . .
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout>
TextInputLayout์
- app:passwordToggleEnabled="true"
- app:passwordToggleTint="@null"
- app:passwordToggleDrawable="@drawable/toggle_icon_status"
์ด 3๊ฐ์ค ํ๋๋ผ๋ ์์ผ๋ฉด ๋ฌธ์ ๊ฐ ์๊ฒผ์๋ค.
๊ฒฐ๊ณผ ํ๋ฉด
์ ์ฉ์ด ์ ๋ผ์๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
'๐ฑ| Android > ๐ | ๊ธฐ๋ก' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Android, Kotlin] android custom dialog ๋ง๋ค๊ธฐ (5) | 2022.11.20 |
---|---|
[Android, Kotlin] Android์์ Apollo๋ฅผ ์ด์ฉํ GraphQL์ฌ์ฉํ๊ธฐ (0) | 2022.10.23 |
[Android/Kotlin] retrofit2 ์ ๋ฆฌ (0) | 2022.05.13 |
[Android] ํ๋ฉด ์ด๋ ๋ฐฉ๋ฒ ์ ๋ฆฌ (0) | 2022.04.12 |
[Android Kotlin] radio button ์์ (0) | 2022.04.11 |