Add image icon inside EditText in android using xml

Set picture file alignment within EditText at left side,right side.

Most of social networking chatting application you have all seen simple image icon at left side of EditText box by clicking on this icon normally smiley, stickers this feature are called as include image inside EditText. So here is the complete step by step tutorial for Add image icon inside EditText in android using xml.

android-project-download-code-button

Note: Upload images into drawable folder.

  • android:drawableLeft=”@drawable/image_name” to set image at left side inside edittext.
  • android:drawableRight=”@drawable/image_name” to set image at right side inside edittext.

How to set Add image icon inside EditText in android using xml.

Code for MainActivity.java file.

package com.android_examples.com.edittextimageadd;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.edittextimageadd.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:ems="10"
 android:drawableLeft="@drawable/demo_image" >

 <requestFocus />
 </EditText>

</RelativeLayout>

Screenshot:

Add image icon inside EditText in android using xml

right side image

Click Here To Download Add image icon inside EditText in android using xml project.

Leave a Reply

Your email address will not be published. Required fields are marked *