change the look of Edit Text box in android
Asked Answered
T

3

16

I want to change the way the edit text view looks like... I have found a few answers but they somehow don't solve my purpose... Please kindly provide solutions.

Thong answered 25/4, 2011 at 12:12 Comment(2)
Please give a better description of what you're trying to archive.Hartford
I want to change the look of the Edit box .. right now it just seems lyk a rectangle with rigid ends .. iw ant to give it a better gui effect.. how do i do dt ?Thong
V
9

Try .

You can do something like this to make a rounded edit box:

Make styyles.xml in values folder.

<solid android:color="#FFFFFF"/>

<stroke
    android:width="2dp"
    android:color="#E7E7E7"
    android:height="10dp"/>

<corners
    android:radius="5dp"/>

You can then use it in xml like :

<EditBox

    style="@style/Edit_box_background"
    other attributes....
    />
Vickey answered 13/9, 2011 at 7:47 Comment(1)
Incomplete answer. Answer by jheneghan is better.Radioscope
M
54

Just to make the comments above a bit clearer:

You should create a file in drawables. e.g: textinputborder.xml..

Then add the following code for the border shape and color to that file:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00000000" />    
<stroke android:width="2.5dp" 
    android:color="#FFFFFF" />
<corners
android:radius="5dp"/>
</shape>     

Then use this shape for the edit text widget inside an activity xml file as required:

<EditText
     android:id="@+id/searchBox"        
     android:layout_width="fill_parent"
     android:layout_height="45dp"
     android:background="@drawable/textinputborder"
     android:hint="@string/Search"
     android:paddingLeft="10dp"
     android:inputType="textVisiblePassword" >

 </EditText>
Mattern answered 14/8, 2013 at 20:34 Comment(0)
V
9

Try .

You can do something like this to make a rounded edit box:

Make styyles.xml in values folder.

<solid android:color="#FFFFFF"/>

<stroke
    android:width="2dp"
    android:color="#E7E7E7"
    android:height="10dp"/>

<corners
    android:radius="5dp"/>

You can then use it in xml like :

<EditBox

    style="@style/Edit_box_background"
    other attributes....
    />
Vickey answered 13/9, 2011 at 7:47 Comment(1)
Incomplete answer. Answer by jheneghan is better.Radioscope
B
5

1. Creating Background Drawable for EditText

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke
        android:width="1.5dp"                   
        android:color="@android:color/darker_gray" />           

    <corners 
        android:radius="4dp" />

</shape>

2. Setting up EditText

<EditText
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:background="@drawable/stroke_box"           //apply background drawable
    android:padding="8dp" />                            //for better effect

enter image description here

Baseman answered 8/2, 2020 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.