Time for action - creating a rounded border

A rectangular shape may also have its corners curved in order to make a rounded rectangle. A rounded rectangle is useful for styling buttons, or creating cleaner looking borders.

  1. Create a new shape resource XML file in the res/drawable directory named rounded_border.xml and open this file in an editor or IDE.
  2. Declare the root element of the file as a rectangle shape:
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    
  3. Set the rectangle stroke to 2dip wide and white in color:
    <stroke android:width="2dip" android:color="#ffffffff" />
    
  4. Pad the rectangle with 8dip of empty space:
    <padding android:top="8dip" android:left="8dip" android:bottom="8dip" android:right="8dip" ...

Get Android User Interface Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.