从MultiAutoCompleteTextView中的建议列表中选择后,使用背景在EditText Gray中创建文本

时间:2016-01-14 08:43:41

标签: android multiautocompletetextview

我的问题是我有一个MultiAutoCompleteTextView,当我输入" @ A"然后应该显示从A开始的单词,我实现了这一点。我正在获取列表,当我点击建议列表时,word会显示在editText中。

但是我希望这个选定的单词是彩色的或设置背景的单词。

例如,当我们在stackoverflow中发布问题时在Tags字段中键入任何单词时,它将在该单词后显示为灰色。

以同样的方式实现。

请提供任何帮助。

由于

2 个答案:

答案 0 :(得分:0)

试试这个:

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)); 

        }
    });

答案 1 :(得分:0)

在drawable文件夹中创建一个名为textbox_selector.xml的xml文件。复制粘贴以下内容:

<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" />

现在只需设置编辑文本

android:background="@drawable/textbox_selector"

现在,如果您触摸您的编辑文本,其颜色将变为深蓝色,当未处于触摸状态或返回原始状态时,颜色将保持浅蓝色。

对于标记,您可以使用这些库

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

希望这有帮助!