开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜