Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change the look of Edit Text box in android

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.

like image 467
Sudhanshu Avatar asked Apr 25 '11 12:04

Sudhanshu


People also ask

How do I change the style of edit text in android Studio?

You can use the attribute style="@style/your_style" that is defined for any widget. The attribute parent="@android:style/Widget. EditText" is important because it will ensure that the style being defined extends the basic Android EditText style, thus only properties different from the default style need to be defined.

How do I change the icon on an edited text?

2- First thing we need to do is to look for icons that we can use them for the android edittext. Right click on res folder → New → Vector Asset . Adjust the size from (24dp x 24dp) to (18dp x 18dp), choose the icon that you want by clicking on the android icon, click “Next” button and then click “Finish”.


3 Answers

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>
like image 112
jheneghan Avatar answered Sep 27 '22 21:09

jheneghan


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....
    />
like image 20
learn_andrd Avatar answered Sep 27 '22 22:09

learn_andrd


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

like image 35
Sam Chen Avatar answered Sep 27 '22 22:09

Sam Chen