본문 바로가기

Mobile/Android

[ Android ] Custom Button 커스텀 버튼 색 변경

반응형


- drawable 폴더에 xml 생성 ( round_button )
- stroke : 테두리
- solid : 배경색
- corners : 모서리 모양

<selector xmlns:android="http://schemas.android.com/apk/res/android">
	//클릭한 경우
    <item android:state_pressed="true">
        <shape>
            <stroke android:width="2dp" android:color="@color/press_blue" />
            <solid android:color="@color/press_blue"/>
            <corners android:bottomLeftRadius="12dp" 
                android:bottomRightRadius="12dp" 
                android:topLeftRadius="12dp" 
                android:topRightRadius="12dp" />
        </shape>
    </item>

	//클릭 안한 경우
    <item android:state_focused="true">
        <shape>
            <stroke android:width="2dp" android:color="@color/unpress_blue" />
            <solid android:color="@color/unpress_blue"/>
            <corners android:bottomLeftRadius="12dp" 
                android:bottomRightRadius="12dp" 
                android:topLeftRadius="12dp" 
                android:topRightRadius="12dp" />
        </shape>
    </item>

    <item>
        <shape>
            <stroke android:width="2dp" android:color="@color/unpress_blue" />
            <solid android:color="@color/unpress_blue"/>
            <corners android:bottomLeftRadius="12dp" 
                android:bottomRightRadius="12dp" 
                android:topLeftRadius="12dp" 
                android:topRightRadius="12dp" />
        </shape>
    </item>
</selector>

 

반응형



*** 적용 ***

<androidx.appcompat.widget.AppCompatButton
...
        android:background="@drawable/blue_corner_round_button" />
반응형