이를 위해 ImageButton을 사용했습니다. xml 방어에서 다음 두 가지 속성을 볼 수 있습니다.
- android : 배경 으로 사용할 드로어 블입니다.
- android : scr- 이 ImageView의 콘텐츠로 드로어 블을 설정합니다.
그래서 우리는 두 개의 드로어 블을 가지고 있습니다 : 배경 1과 소스. 예제 소스는 triagle (drawable / trianlge)입니다.
|\
| \
|__\
그리고 배경은 정사각형 (드로어 블 / 정사각형)입니다.
_____________
| |
| |
| |
| |
|____________|
다음은 ImageButton xml의 예입니다.
<ImageButton
...
android:src="@drawable/triangle"
android:background="@drawable/square">
결과:
_____________
| |
| |\ |
| | \ |
| |__\ |
|____________|
또한 정사각형 드로어 블은 여러 가지 상태 (눌림, 초점)를 가질 수 있습니다. 패딩을 사용하여 배경 드로어 블 크기를 확장 할 수 있습니다.
경우에 따라 Android Compat Actionbar의 배경 드로어 블 예는 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_disabled_holo_dark" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/abc_list_selector_disabled_holo_dark" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_dark" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_dark" />
<item android:state_focused="true" android:drawable="@drawable/abc_list_focused_holo" />
<item android:drawable="@android:color/transparent" />
</selector>