How To Create EditText with Custom Shape

How To Create EditText with Custom Shape in Android Studio

The result will show as below screen.
Category A : EditText with solid color.
Category B : EditText with stroke color.
Category C : EditText with stroke color & corners.
Category D : EditText with stroke color, solid color & corners.
Category E : EditText with stroke color, gradient color & corners.


Step 1 : right click drawable under res and choose New -> Drawable resource file 


Step 2 : put in File name "edittext"


Step 3 : layout have to create a EditText with id "et".
Layout Name : activity_main.xml


<EditText
    android:background="@drawable/edittext"    
    android:id="@+id/et"    
    android:layout_width="match_parent"    
    android:layout_height="wrap_content"    
    app:layout_constraintEnd_toEndOf="parent"    
    app:layout_constraintStart_toStartOf="parent"    
    app:layout_constraintTop_toTopOf="parent" />


Category A : EditText with solid color. (add in below into edittext.xml)


<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">    
   <item>        
      <shape android:shape="rectangle" >            
         <solid android:color="@color/colorAccent"/>        
      </shape>    
   </item>
</layer-list>


Category B : EditText with stroke color. (add in below into edittext.xml)


<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">    
   <item>        
      <shape android:shape="rectangle" >            
         <stroke android:width="1dp" android:color="@color/colorAccent"/>        
      </shape>    
   </item>
</layer-list>


Category C : EditText with stroke color & corners. (add in below into edittext.xml)


<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">    
   <item>        
      <shape android:shape="rectangle" >            
         <stroke android:width="1dp" android:color="@color/colorAccent"/>            
         <corners android:radius="10dp"/>        
      </shape>    
   </item>
</layer-list>


Category D : EditText with stroke color, solid color & corners. (add in below into edittext.xml)


<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">    
   <item>        
      <shape android:shape="rectangle" >            
         <stroke android:width="1dp" android:color="@color/colorAccent"/>            
         <solid android:color="@color/colorPrimary"/>            
         <corners android:radius="10dp"/>        
      </shape>    
   </item>
</layer-list>


Category E : EditText with stroke color, gradient color & corners. (add in below into edittext.xml)


<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">    
   <item>        
      <shape android:shape="rectangle" >            
         <stroke android:width="1dp" android:color="@color/colorAccent"/>            
         <corners android:radius="10dp"/>            
         <gradient android:startColor="#000000" android:endColor="#FFFFFF" 
         android:angle="90"/>
      </shape>    
   </item>
</layer-list>


THE END. HAPPY CODING. :)


No comments:

Post a Comment

Welcome To My Android Tutorial Lesson. Now this blogger cover : Android Studio Tutorial 1.  How To Start / Create a new project...