ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ


edit text๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ปค์„œ๊ฐ€ ๋†“์—ฌ์ ธ ์žˆ๋Š” ๋ถ€๋ถ„์˜ underline์˜ ์ƒ‰๊น”์ด ๋ฐ”๋€Œ๊ธธ ์›ํ•  ๋•Œ selector๋ฅผ ํ†ตํ•ด์„œ ์ผ๊ด„์ ์œผ๋กœ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ์ด๋‹ค.


์ด ์„ธ ๊ฐœ์˜ xml ํŒŒ์ผ์ด ํ•„์š”ํ•œ๋ฐ ํด๋ฆญ ์‹œ์— ๋‚˜ํƒ€๋‚ผ ์ƒ‰๊น”์„ ์ง€์ •ํ•˜๋Š” xml ํŒŒ์ผ, ๊ธฐ๋ณธ ์ƒํƒœ์ผ ๋•Œ์˜ ์ƒ‰๊น”์„ ์ง€์ •ํ•˜๋Š” xmlํŒŒ์ผ, ๊ทธ๋ฆฌ๊ณ  ์ด ๋‘๊ฐœ๋ฅผ ์ด์šฉํ•ด์„œ selector์˜ ํ˜•ํƒœ์˜ xmlํŒŒ์ผ์ด ํ•„์š”ํ•˜๋‹ค.


edt_under_selected.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:bottom="1dp"
        android:left="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <shape android:shape="rectangle" >
            <stroke
                android:width="1px"
                android:color="#00ecc7" />
 
            <solid android:color="#00FFFFFF" />
 
            <padding
                android:bottom="5dp"
                android:left="5dp"
                android:right="5dp"
                android:top="5dp" />
        </shape>
    </item>
</layer-list>

cs




edt_under_normal.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:bottom="1dp"
        android:left="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <shape android:shape="rectangle" >
            <stroke
                android:width="0.02px"
                android:color="#FF000000" />
 
            <solid android:color="#00FFFFFF" />
 
            <padding
                android:bottom="5dp"
                android:left="5dp"
                android:right="5dp"
                android:top="5dp" />
        </shape>
    </item>
</layer-list>
cs


edt_underline.xml

1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/edt_bg_selected" android:state_focused="true"/>
    <item android:drawable="@drawable/edt_bg_normal" android:state_focused="false"/>
</selector>
cs

์ž‘์„ฑ ํ›„์— ์ ์šฉํ•˜๊ณ  ์‹ถ์€ ํ•ด๋‹น EditText์— android:background="@drawable/edt_underline"
์„ ์ž‘์„ฑํ•ด์ฃผ๋ฉด ๋. 
๋‘๊ป˜๋ผ๋˜์ง€ ์ƒ‰๊น”๊ณผ ๊ฐ™์€ ์†์„ฑ๋“ค์€ ์ž๊ธฐ ์ž…๋ง›์— ๋งž๊ฒŒ๋” ์ž‘์„ฑํ•˜๋ฉด ๋ชจ๋‘ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค~

์ฐธ๊ณ ๋กœ ์ € hint๋ฌธ์ด ํด๋ฆญ์‹œ์— ์˜ฌ๋ผ๊ฐ€๋Š” ๋ชจ์…˜์€ android.support.design.widget.TextInputLayout
์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค 


'Android' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Android ์•ฑ ๊ถŒํ•œ ์ฒดํฌ ๋ฐ ํ—ˆ์šฉ  (3) 2018.03.22
๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
๊ธ€ ๋ณด๊ด€ํ•จ