한 걸음 두 걸음

android custom button 커스텀버튼 만들기 본문

FrontEnd/Android

android custom button 커스텀버튼 만들기

언제나 변함없이 2019. 3. 13. 05:40
반응형

1. drawable image에 button clicked event 추가하기

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:drawable="@drawable/파일이름"/>
    <item android:state_focused="true"
        android:drawable="@drawable/파일이름"/>
    <item android:drawable="@drawable/파일이름"/>
</selector>

위의 xml파일을 가져와서 background속성으로 주면 된다.

2. xml 파일 자체로만 custom하기

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_pressed="true">
        <shape > <solid android:color="#c71a1a"/>
            <stroke android:width="2dp" android:color="#4b4c4c"/> 
            <corners android:bottomLeftRadius="12dp" android:bottomRightRadius="12dp" android:topLeftRadius="12dp" android:topRightRadius="12dp"/> 
        </shape> </item> <item android:state_pressed="false"> 

    <shape >
        <gradient android:angle="270" android:endColor="#c71a1a" android:startColor="#ffb9b9"/>
        <stroke android:width="2dp" android:color="#4b4c4c"/> 
        <corners android:bottomLeftRadius="12dp" android:bottomRightRadius="12dp" android:topLeftRadius="12dp" android:topRightRadius="12dp"/>
    </shape>
</item>
</selector>

따로 image가 들어가있지는 않다.

//imageButton도 마찬가지로 쓰인다.

반응형