Android: How to place an edge around the button
So I want to make my button have white edges/border with a black background, is the开发者_运维问答re a simple solution to do this in my xml?
Yup! Make a new XML file in your res/drawable directory, and then create a shape drawable via XML. Here's an example for a 3-px rounded black rectangle with a 2-px white border:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="3"
/>
<stroke
android:width="2"
android:color="#FFFFFFFF"
/>
<solid
android:color="#FF000000"
/>
</shape>
Then just set this drawable as the background of your button, for example:
<Button
android:background="@drawable/my_xml_file"
/>
The developer site has a great reference on creating Shape Drawables via XML.
精彩评论