Drawable로 다양한 소재를 만들어 봤습니다.

11650 단어 AndroidJava

Drawable Resource 문서


이미지


각 버튼에는 터치 피드백이 있습니다.그림자가 있는 버튼은 만지면 움푹 들어간다.

xml


샘플의 각 재료는 단일 파일로 완성되기 때문에 컬러 코드 등은 비교적 많이 쓸 수 있다.
내용은 상술한 문서를 보면 간단하게 이해할 수 있을 것 같다.

녹색 라벨


sample.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#009688" />
    <corners android:radius="8dp" />

</shape>

주황색 라벨


sample.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#00000000" />
    <corners android:radius="8dp" />
    <stroke android:width="1dp" android:color="#ff9800" />

</shape>

파란색 원형 단추


sample.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape android:shape="oval">
            <solid android:color="#aa00bcd4" />
        </shape>
    </item>

    <item android:state_focused="true">
        <shape android:shape="oval">
            <solid android:color="#aa00bcd4" />
        </shape>
    </item>

    <item>
        <shape android:shape="oval">
            <solid android:color="#00bcd4" />
        </shape>
    </item>

</selector>

파란색 단추


sample.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape>
            <solid android:color="#aa00bcd4" />
            <corners android:radius="8dp" />
        </shape>
    </item>

    <item android:state_focused="true">
        <shape>
            <solid android:color="#aa00bcd4" />
            <corners android:radius="8dp" />
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="#00bcd4" />
            <corners android:radius="8dp" />
        </shape>
    </item>

</selector>

파란색 줄무늬의 단추


sample.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape>
            <solid android:color="#e3e3e3" />
            <corners android:radius="8dp" />
            <stroke android:width="1dp" android:color="#00bcd4" />
        </shape>
    </item>

    <item android:state_focused="true">
        <shape>
            <solid android:color="#e3e3e3" />
            <corners android:radius="8dp" />
            <stroke android:width="1dp" android:color="#00bcd4" />
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="#00000000" />
            <corners android:radius="8dp" />
            <stroke android:width="1dp" android:color="#00bcd4" />
        </shape>
    </item>

</selector>

파란색 섀도우가 달린 버튼.


sample.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <layer-list>
            <item android:top="3dp">
                <shape>
                    <solid android:color="#00bcd4" />
                    <corners android:radius="8dp" />
                </shape>
            </item>
        </layer-list>
    </item>

    <item android:state_focused="true">
        <layer-list>
            <item android:top="3dp">
                <shape>
                    <solid android:color="#00bcd4" />
                    <corners android:radius="8dp" />
                </shape>
            </item>
        </layer-list>
    </item>

    <item>
        <layer-list>
            <item>
                <shape>
                    <solid android:color="#dddddd" />
                    <corners android:radius="8dp"/>
                </shape>
            </item>
            <item android:bottom="3dp">
                <shape>
                    <solid android:color="#00bcd4" />
                    <corners android:radius="8dp"/>
                </shape>
            </item>
        </layer-list>
    </item>

</selector>

좋은 웹페이지 즐겨찾기