0

My Question is that I have a MultiAutoCompleteTextView in which when I typed "@A" then the words Starting from A should be displayed and I achieved that. I am getting the list and when I clicked on suggested list the word is displayed in the editText.

But I want that selected word to be some coloured or set background to the word.

For example when we type any words in Tags field when posting question in stackoverflow it will be grayed after that word.

In the same way I want to achieve.

Any kind of help please.

Thanks

Mohd Asif Ahmed
  • 1,880
  • 2
  • 15
  • 29
  • IMO you can refer to my answer at http://stackoverflow.com/questions/33417887/how-do-i-highlight-the-searched-text-in-my-search-filter then apply to your adapter – BNK Jan 28 '16 at 01:40

2 Answers2

0

Try this:

myMultiAutocompleteTextView.setOnItemClickListener( new OnItemClickListener() {
        @Override
        public void onItemClick( AdapterView<?> arg0, View arg1, int position, long id ) {

            //set the color you want
            myMultiAutocompleteTextView.setTextColor(getResources().getColor(android.R.color.holo_red_light)); 

            //set the background color you want
            myMultiAutocompleteTextView.setBackgroundColor(getResources().getColor(android.R.color.holo_purple)); 

        }
    });
Nicolas Cortell
  • 659
  • 4
  • 16
0

Make a xml file named as textbox_selector.xml in your drawable folder. Copy Paste the following:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/box_light_blue_bg" android:state_enabled="true" android:state_window_focused="false" />
<item android:drawable="@drawable/box_light_blue_bg" android:state_enabled="false" android:state_window_focused="false" />
<item android:drawable="@drawable/box_dark_blue_bg" android:state_pressed="true" />
<item android:drawable="@drawable/box_dark_blue_bg" android:state_enabled="true" android:state_focused="true" />
<item android:drawable="@drawable/box_light_blue_bg" android:state_enabled="true" />
<item android:drawable="@drawable/box_dark_blue_bg" android:state_focused="true" />
<item android:drawable="@drawable/box_light_blue_bg" />

Now wherever your edit text is just set

android:background="@drawable/textbox_selector"

Now if you touch your edittext, its color will change to dark blue and when not in touched state or back to orignal state the color will remain light blue.

For tagging you can use these library

https://github.com/kpbird/chips-edittext-library https://github.com/DavidPizarro/AutoLabelUI

Hope this helps!

Udit Kapahi
  • 2,277
  • 1
  • 27
  • 25