vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, June 20, 2012

Android EditText control design and properties event



In this article, you will learn to apply design to android edittext control to get the text input from the user by using eclipse.
But before apply the below design you must know the basic knowledge to add xml file in drawable folder
1.     Add edit text control to the layout
<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10">
    2. Set the water mark text in edit text control
You can also set the watermark text using an attributes
android:hint="@string/enter_your_email"
3.Apply Designs to edittext control
Then you can apply the design using by adding the below xml file in drawable folder.
Steps to follow:
Right Click the Drawable folder ->add new xml file with shape layout and add the below code.
css.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_focused="true">
    <shape>
        <solid android:color="#FF8000"/>
        <stroke
            android:width="2.3dp"
            android:color="#FF8000" />
         <corners
            android:radius="15dp" />
    </shape>
</item>
<item android:state_pressed="true" android:state_focused="false">
    <shape>
        <solid android:color="#FF8000"/>
        <stroke
            android:width="2.3dp"
            android:color="#FF8000" />     
        <corners
            android:radius="15dp" />      
    </shape>
</item>
<item android:state_pressed="false" android:state_focused="true">
    <shape>
        <solid android:color="#FFFFFF"/>
        <stroke
            android:width="2.3dp"
            android:color="#FF8001" /> 
        <corners
            android:radius="15dp" />                         
    </shape>
</item>
<item android:state_pressed="false" android:state_focused="false">
    <shape>
        <gradient
            android:startColor="#F2F2F2"
            android:centerColor="#FFFFFF"
            android:endColor="#FFFFFF"
            android:angle="270"
        />
        <stroke
            android:width="0.7dp"               
            android:color="#BDBDBD" />
        <corners
            android:radius="15dp" />           
    </shape>
</item>
<item android:state_enabled="true">
    <shape>
        <padding
                android:left="4dp"
                android:top="4dp"
                android:right="4dp"
                android:bottom="4dp"
            />
    </shape>
</item>
</selector>

Now the main xml layout add the css.xml file in edit text control
  <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textColor="#372c24"
        android:hint="@string/enter_your_email"
        android:background="@drawable/css" >
     
    </EditText>


4. Events in EditText control.

Here the list of events used in Edit text control

1.       When a user clicks on the control. In this case, register a listener using the setOnClickListener() method.
2.      When a user long-clicks on the control. In this case, register a listener using the setOnLongClickListener() method.
3.      When a user presses a key within the control. In this case, register a listener using the setOnKeyListener() method.
4.      When a user changes focus to or from the control. In this case, register a listener using the setOnFocusChangedListener() method.

I hope you like this article ..share your comments here

0 comments:

Post a Comment