我使用AutoCompleteTextView在我自己的服务器上进行搜索。我使用AutoCompleteTextView作为在用户输入时向他们显示建议的一种方式。就这样。由于我的AutoCompleteTextView用于搜索,因此我想将SearchView添加到该字段中。我该怎么做呢?
以下命令不起作用
SearchView search = new SearchView(this);
int resId = getResources().getIdentifier("search_button", "id", "android");
ImageView img = (ImageView) search.findViewById(resId);
Drawable left = img.getDrawable();
mTextSearch.setCompoundDrawables(left, null, null, null);
//mTextSearch is the AutoCompleteTextView发布于 2015-04-23 00:12:29
有一种方法可以通过提示文本显示搜索图标,如下所示
String hintText = getResources().getString(where);
Drawable searchIcon = getResources().getDrawable(btn_search);
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
ssb.append(hintText);
int textSize = (int) (autoCompleteTextView.getTextSize() * 1.25);
searchIcon.setBounds(0, 0, textSize, textSize);
ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
autoCompleteTextView.setHint(ssb);我不知道这是否真的是您想要的,但这是一种方法;)缺点是在输入文本时搜索图标消失!
https://stackoverflow.com/questions/28282478
复制相似问题