Rounded buttons on android

7

I have this:

In drawable a file called: boton_redondo.xml whose content is:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#F5D0A9"/>
    <corners android:radius="20dip" />
</selector>

In the button that is included in the layout I have:

 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Modificar"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:typeface="sans"
        android:background="@drawable/boton_redondo"/>

The result is that the button appears only with the word Modify, with no background or anything, as if it were a TextView.

What am I doing wrong?

Thank you in advance.

Greetings

    
asked by 04.05.2016 в 13:11
source

1 answer

9

For what you want to achieve, do not use a StateListDrawable (selector) uses a ShapeDrawable (shape) :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <solid android:color="#ffffff"/>    

    <stroke android:width="3dp"
            android:color="#ff000000"/>

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"/> 

    <corners android:radius="30px"/> 
</shape>

selector, is used when you want to create a StateListDrawable . To create a drawable to generate rounded edges in your botton you must use a ShapeDrawable .

You can review the documentation of the types of drawable used in android and its structure:

link

As an example, the previous .xml is stored in the folder /drawable with the name borde_redondo.xml and in our button we load it as background:

<Button
    android:id="@+id/btnRedondo"
    android:layout_width="159dp"
    android:layout_height="wrap_content"
    android:text="bordes redondos"
    android:textColor="#000000"
    android:background="@drawable/borde_redondo"/>

We will have as a result:

    
answered by 04.05.2016 в 13:51