Android Development: How Can I Make An EditText Pl

2019-02-17 04:30发布

问题:

As the title says, I've seen EditTexts where they are just plain white with no smooth corners or orange android border when you highlight it etc.

Like it looks in this app: http://s1.appbrain.com/screen?id=-2631427781674403509&i=1

回答1:

You need to create a custom background 9-patch image like this one and put it to /res/drawable directory. Here is the tutorial for 9-patch images. Then you need to apply the image as a background for your EditText using android:background attribute.

Here is a sample layout xml:

<EditText
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:background="@drawable/white_bg"
    android:text="Test"
    android:layout_marginBottom="5dip" /> 

<EditText
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:background="@drawable/white_bg"
    android:text="Currently focused" />

And here is the result: