Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change style of a default EditText

I am creating three EditTexts in my xml file using code like this:

<EditText     android:id="@+id/name_edit_text"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/profile_image_view_layout"     android:layout_centerHorizontal="true"     android:layout_marginLeft="10dp"     android:layout_marginRight="10dp"     android:layout_marginTop="20dp"     android:ems="15"     android:hint="@string/name_field"     android:inputType="text" /> 

When I run the app, it looks like this on my device:

enter image description here

But I want it to look like this, without using any background image:

enter image description here

So how can that be done? Any ideas or suggestions will be helpful.

like image 228
Rahul Avatar asked Jul 03 '13 13:07

Rahul


People also ask

How do I change the default text in EditText?

You can use EditText. setText(...) to set the current text of an EditText field.

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 edit a EditText file?

How to include a Edittext in an Android App: First of all, create a new Android app, or take an existing app to edit it. In both the case, there must be an XML layout activity file and a Java class file linked to this activity. Open the Activity file and include a Edittext field in the layout (activity_main.

How do I edit EditText Uneditable?

If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.


1 Answers

Create xml file like edit_text_design.xml and save it to your drawable folder

i have given the Color codes According to my Choice, Please Change Color Codes As per your Choice !

 <?xml version="1.0" encoding="utf-8"?>   <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >  <item>     <shape>         <solid android:color="#c2c2c2" />     </shape> </item>  <!-- main color --> <item     android:bottom="1.5dp"     android:left="1.5dp"     android:right="1.5dp">     <shape>         <solid android:color="#000" />     </shape> </item>  <!-- draw another block to cut-off the left and right bars --> <item android:bottom="5.0dp">     <shape>         <solid android:color="#000" />     </shape> </item>  </layer-list> 

your Edit Text Should contain it as Background :

add android:background="@drawable/edit_text_design" to all of your EditText's

and your above EditText should now look like this:

      <EditText         android:id="@+id/name_edit_text"         android:background="@drawable/edit_text_design"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/profile_image_view_layout"         android:layout_centerHorizontal="true"         android:layout_marginLeft="10dp"         android:layout_marginRight="10dp"         android:layout_marginTop="20dp"         android:ems="15"         android:hint="@string/name_field"         android:inputType="text" /> 
like image 114
Tarsem Singh Avatar answered Sep 29 '22 17:09

Tarsem Singh