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.
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.
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>
精彩评论