android source

textview touch color 변화

리오파파 2024. 10. 24. 08:48

textview 에 background 설정

        <TextView
        . . .
            android:background="@drawable/touched"
            />

 

drawable/touched.xml 에 shape 정의

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- State when the view is pressed (touched down) -->
    <item android:state_pressed="true">
        <shape>
            <solid android:color="#CC4455" /> <!-- Touched color -->
            <corners android:radius="16dp" />
            <stroke android:width="1dp" android:color="#AA3344" /> <!-- Optional border color when pressed -->
        </shape>
    </item>
    
    <!-- Default state (when touch is released or not pressed) -->
    <item>
        <shape>
            <solid android:color="#FFCC33" /> <!-- Normal color -->
            <corners android:radius="16dp" />
            <stroke android:width="1dp" android:color="#FFAA00" /> <!-- Optional border color -->
        </shape>
    </item>
</selector>

 

 

'android source ' 카테고리의 다른 글

res > mipmap > filename 읽기  (0) 2024.12.10
TextView clicked animation  (0) 2024.12.03
Sound, media 대신 ring mode로 설정  (0) 2024.10.19
sub class 에서 localbroadcaster로 main call 하기  (0) 2024.09.21
PhoneShaking Detect  (1) 2024.09.17