[Android] layout select color change (레이아웃 선택 컬러 변경)

2021. 7. 23. 17:11모바일/Android_Java

[Android] layout select color change (레이아웃 선택 컬러 변경)

xml에 selector값 설정

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="false" android:state_pressed="false">
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <solid android:color="#ffffff" />
            <stroke android:width="1dp" android:color="#cccccc" />
        </shape>
    </item>
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <solid android:color="@color/primary_orange" />
        </shape>
    </item>
    <item android:state_selected="true">
        <shape android:shape="rectangle">
            <corners android:radius="4dp" />
            <solid android:color="@color/primary_orange" />
        </shape>
    </item>
</selector>

레이아웃 android:background 속성에 위에 작성한 xml값 부여

<RelativeLayout
                    android:id="@+id/tab_button_00"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dimen_45"
                    android:layout_marginTop="@dimen/dimen_15"
                    android:background="@drawable/bg_cert_list">