For this purposes I was using ImageButton.
In xml defenition you will see these two attributes:
- android:background - A drawable to use as the background.
- android:scr - Sets a drawable as the content of this ImageView.
So we have two drawables: background one and source.
In you example source will be triagle(drawable/trianlge):
|\
| \
|__\
And background is square(drawable/square):
_____________
| |
| |
| |
| |
|____________|
Here is example of ImageButton xml:
<ImageButton
...
android:src="@drawable/triangle"
android:background="@drawable/square">
Result:
_____________
| |
| |\ |
| | \ |
| |__\ |
|____________|
Also square drawable, could have several different states(pressed, focused). And you could expand backgroud drawable size using paddings.
Just in case, here is example for background drawable from Android Compat Actionbar:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<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>