Reputation: 21595
I was able to draw a cross button like this with a lot of code and effort:
This little cross took me all of this code:
<item >
<shape android:shape="rectangle">
<solid android:color="#bbb" />
<stroke
android:width="1px"
android:color="@color/black" />
<padding android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp"
/>
<size
android:width="18dp"
android:height="18dp" />
</shape>
</item>
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="@color/black" />
<size
android:width="10dp"
android:height="10dp" />
</shape>
</rotate>
</item>
<item>
<rotate
android:fromDegrees="135"
android:toDegrees="135"
android:pivotX="50%"
android:pivotY="50%">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="@color/black" />
<size
android:width="10dp"
android:height="10dp" />
</shape>
</rotate>
</item>
I would like to ask someone experienced how to draw the following picture more easily:
Upvotes: 1
Views: 2827
Reputation: 343
This works for me
<ImageButton
android:layout_width="36dp"
android:layout_height="36dp"
android:background="@drawable/btn_expand_up"
android:src="@drawable/ic_up_24dp"/>
Upvotes: 1
Reputation: 6717
Drawing your own buttons is fun, but if you would like to save yourself some time and effort, you should check out this site, which provides over 1500 free icon resources for your Android application in different resolutions.
Additionally, you can download the official android icon pack which provides more than enough standard icons in mdpi, hdpi, xhdpi and xxhdpi.
Lastly, if none of these icons would suit you, you can create your own icons from your own image resources using the Launcher Icon Generator.
In your example, you probably would like an icon looking like this (taken from the official android icon pack, see above link):
Which is easily added in your drawable
folder and then set as a background to an ImageView
element:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/your_icon" />
Upvotes: 1
Reputation: 349
That's not a lot of code at all...in my humble opinion i think that you took the right approach. If you do not have the image and need to build it manually, declaring it in xml let you avoid to write code and keep things organized.
Upvotes: 0