在Android SearchView中我制作了一个TextView并添加了#34;本网站"然后将视图转换为位图并使用可绘制的形状添加范围。
我不希望我的光标在Span之前输入,setSelection
似乎不适合我
final SearchView sv = new SearchView(getActivity());
final String tokenName = "This Site";
final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = createSearchTokenTextView(tokenName);
BitmapDrawable bd = (BitmapDrawable) convertViewToDrawable(tv);
bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
sb.append(tokenName + " ");
sb.setSpan(new ImageSpan(bd), sb.length() - (tokenName.length() + 1), sb.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Selection.setSelection(sb, 0, sb.toString().length());
sv.setQuery(sb, false);