For this, I used ImageButton. In xml defenition you will see these two attributes:
- Android: Background . Select to use as background.
- android: scr . Sets the ability to draw as the contents of this ImageView.
So, we have two possibilities: background one and source. In your example, the source will be a triagle (drawable / trianlge):
|\ | \ |__\
And the background is square (drawable / square):
_____________ | | | | | | | | |____________|
Here is an example ImageButton xml:
<ImageButton ... android:src="@drawable/triangle" android:background="@drawable/square">
Result:
_____________ | | | |\ | | | \ | | |__\ | |____________|
In addition, a square drawable can have several different states (pressed, focused). And you can increase the size of the cut backgroud with paddings.
Just in case, here is an example for the background retrieved from the Android Android action bar:
<?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>
molokoka Dec 05 '13 at 12:41 2013-12-05 12:41
source share