Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is an easier way than the one written by CommonsWare. Just create a drawable resource that specifies the way the <code>EditText</code> will be drawn:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- res/drawable/rounded_edittext.xml --&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"&gt; &lt;solid android:color="#FFFFFF"/&gt; &lt;corners android:bottomRightRadius="15dp" android:bottomLeftRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/&gt; &lt;/shape&gt; </code></pre> <p>Then, just reference this drawable in your layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dip" android:background="@drawable/rounded_edittext" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>You will get something like:</p> <p><img src="https://i.stack.imgur.com/R03Gk.png" alt="alt text"></p> <h3>Edit</h3> <p>Based on Mark's comment, I want to add the way you can create different states for your <code>EditText</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- res/drawable/rounded_edittext_states.xml --&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/rounded_focused" /&gt; &lt;item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/rounded_focused" /&gt; &lt;item android:state_enabled="true" android:drawable="@drawable/rounded_edittext" /&gt; &lt;/selector&gt; </code></pre> <p>These are the states:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- res/drawable/rounded_edittext_focused.xml --&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"&gt; &lt;solid android:color="#FFFFFF"/&gt; &lt;stroke android:width="2dp" android:color="#FF0000" /&gt; &lt;corners android:bottomRightRadius="15dp" android:bottomLeftRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/&gt; &lt;/shape&gt; </code></pre> <p>And... now, the <code>EditText</code> should look like:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:background="@drawable/rounded_edittext_states" android:padding="5dip"/&gt; &lt;/LinearLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload