user590849
user590849

Reputation: 11765

add border to edittext control in android

i want to add a grey border to my edittext control. How do i add such a border, either via xml or programatically.

thank you in advance.

Upvotes: 2

Views: 7886

Answers (2)

Julian Suarez
Julian Suarez

Reputation: 4521

If you put a custom background you lose the nice(Android 4.0+) default background from android, then what I did is just to put a frame layout with a padding of 1dp and set the background of the FrameLayout instead of the EditText

<FrameLayout
    android:id="@+id/frameLayoutValueContainer"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.6"
    android:padding="1dp"
    android:background="@android:color/black" >

    <EditText
        android:id="@+id/editText_input"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" />
</FrameLayout>

Upvotes: 1

Michael
Michael

Reputation: 54705

You need to make a nine-patch image and set it as a background of your EditText control:

<EditText android:background="@drawable/your_background"/>

It's better to use nine-patch because of its scaling capability.

Upvotes: 3

Related Questions