Android(安卓)搜索到的关键字改变颜色
16lz
2021-12-04
private class MyAdapter extends BaseAdapter {@Overridepublic int getCount() {return mAnchors.size();}@Overridepublic Object getItem(int position) {return mAnchors.get(position);}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int arg0, View arg1, ViewGroup arg2) {LayoutInflater mInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);View mView = mInflater.inflate(R.layout.cell_anchor, arg2, false);ImageView mImage = (ImageView) mView.findViewById(R.id.search_anchor_image);TextView mTextName = (TextView) mView.findViewById(R.id.search_anchor_name);TextView mTextId = (TextView) mView.findViewById(R.id.search_anchor_id);int chageTextColor;ForegroundColorSpan redSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue));LiveRoom anchor = mAnchors.get(arg0);SpannableStringBuilder builder = new SpannableStringBuilder(anchor.anchorName);chageTextColor = anchor.anchorName.indexOf(mSearchText);if (chageTextColor != -1) {builder.setSpan(redSpan, chageTextColor, chageTextColor+ mSearchText.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);mTextName.setText(builder);} elsemTextName.setText(anchor.anchorName);SpannableStringBuilder builder1 = new SpannableStringBuilder(String.valueOf(anchor.anchorId));chageTextColor = String.valueOf(anchor.anchorId).indexOf(mSearchText);if (chageTextColor != -1) {builder1.setSpan(redSpan, chageTextColor, chageTextColor+ mSearchText.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);mTextId.setText(builder1);} elsemTextId.setText(String.valueOf(anchor.anchorId));return mView;}}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer