Customize Edittext input character to image?

I want to customize an edittext when user input a character and then edittext changes it to image.
Look like the image : enter image description here

Note : ● is an image not a symbol.

  • Multiple Selection Spinner
  • How to disable status bar / notification bar on android programmatically?
  • Android: How to bind spinner to custom object list?
  • getActivity().findViewById returns null, called from fragment onActivityCreated
  • cannot access memory at address 0X1 after setting up gdb and eclipse to debug shared library from Android Application
  • Android AsyncTask example and explanation
  • Related posts:

    Programmatically collapse a group in ExpandableListView
    Media Recorder with Google Vision API
    Navigation Drawer and VideoView in android
    display view on top of action bar
    Android 4.2 developer settings still unavailable
    Is using Android shared preferences for storing large amounts of data a good idea?
  • Selector on background color of TextView
  • startActivityForResult() from a Fragment and finishing child Activity, doesn't call onActivityResult() in Fragment
  • Fragment in ViewPager using FragmentPagerAdapter is blank the second time it is viewed
  • android textview padding between lines
  • Real-time audio processing in Android
  • Android WebView not loading a JavaScript file, but Android Browser loads it fine
  • 4 Solutions collect form web for “Customize Edittext input character to image?”

    you need to extend PasswordTransformationMethod and use setTransformationMethod method of EditText.

    edt.setTransformationMethod(new CustomPasswordTransformationMethod());

    and paste this CustomPasswordTransformationMethod

    class CustomPasswordTransformationMethod extends PasswordTransformationMethod {
        public CharSequence getTransformation(CharSequence source, View view) {
            return new PasswordCharSequence(source);
        private class PasswordCharSequence implements CharSequence {
            private CharSequence source;
            public PasswordCharSequence(CharSequence source) {
                this.source = source;
            public char charAt(int index) {
                if(index>4) //your own condition, when you want to hide characters.
                    return 0x2022; // change this to bullets you want like '*' or '.'
                return source.charAt(index);
            public int length() {
                return source.length();
            public CharSequence subSequence(int start, int end) {
                return source.subSequence(start, end);

    Above code will write character as it is upto 5 character, after that it will print bullets in EditText.

    Reference taken from this post


    Finally here is your answer :

    Spannable.Factory spannableFactory;
    int lastIndex = -1;
    spannableFactory = Spannable.Factory

    1. add addTextChangedListener in your EditText.

        TextWatcher watcher = new TextWatcher() {
           public void beforeTextChanged(CharSequence s, int start, int count, int after) {
           public void onTextChanged(CharSequence s, int start, int before, int count) {
               if (start>4) {
                   mEditText.setText(getIconText(context, s, start));
           public void afterTextChanged(Editable s) {
    1. Convert your drawable into Spannable

      public Spannable getIconText(Context context, CharSequence text, int index) {
         Spannable spannable = spannableFactory.newSpannable(text);
         if (index>lastIndex) {
             spannable.setSpan(new ImageSpan(context, R.drawable.bullet_point),
                   index, index + 1,
         return spannable;

    enter image description here

    Let’s say if you want to replace the character b with character . Then you can add TextWatcher for this, which looks like this

     myEditText.addTextChangedListener(new TextWatcher() {
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                StringBuilder myText = new StringBuilder(myEditText.getText().toString());
                if (myText.toString().contains("b")){ //If this contains b
                    myEditText.setText(myText.toString()); //Sets the string to EditText
                    myEditText.setSelection(myText.length()); //Moves cursor to the last after replacing
            public void afterTextChanged(Editable s) {


    we can use setCompoundDrawablesWithIntrinsicBounds for Placing the image but cant place it as a character at exact position. we can define the bounds only.

    use property of edittext inputtype in your xml


    Try this in your code. doc

        EditText text = (EditText) findViewById(;
        text.setCompoundDrawablesWithIntrinsicBounds(null, null,
                           getResources().getDrawable(R.drawable.myDrawable), null);
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.