Android EditText Control Styling using styles.xml

Android EditText Control Styling : Android EditText Control is a thin veneer over TextView that configures itself to be editable. Its base class is android.widget. User can enter text values in Edit text control. You can configure Android EditText control to accept different values. For instance, EditText control can be configured to accept only numeric values where user is required to enter his/her age, or EditText control can be configured to accept only alphabets  where name is required.

EditText control can be Styled using styles.xml file to make it more attractive and stylish.

Android EditText Control Styling using styles.xml :

Add a style element as below in your res>values>styles.xml : 

<style name="MyEditTextStyle" parent="android:Widget.EditText">
 <item name="android:textColor">#400000</item>
 <item name="android:textStyle">bold</item>
 <item name="android:padding">10dp</item>
 <item name="android:typeface">monospace</item>
 <item name="android:background">@android:drawable/editbox_background_normal</item>
 <item name="android:textSize">20sp</item>
 </style>

And supply this style name to your EditText control in design file :

res>layout>activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#fff"
 android:orientation="vertical"
 android:padding="10dp" >

<EditText
 android:id="@+id/edtName"
 style="@style/MyEditTextStyle"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_margin="5dp"
 android:hint="Enter your Name"
 android:inputType="text"
 android:textColor="#000" />

</LinearLayout>

This will result into following design:

Android Edittext Control Styling

Android Edittext Control via Style

Please also see : Android Beginners Tutorial.



2 thoughts on “Android EditText Control Styling using styles.xml”

  1. Pingback: Android Beginners Tutorial - A List of Beginner Tutorials • ParallelCodes;

  2. Pingback: Android Edittext Style? Best 6 Answer - Brandiscrafts.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.