Android開發 高亮顯示搜尋結果

2021-06-28 07:34:46 字數 654 閱讀 6063

在顯示搜尋結果的時候,我們一般會在結果中高亮顯示搜尋的關鍵字,為此好一陣搜尋資料,不過找到方法後,卻發現相當的簡單,先上效果圖:

設定方法:

spannablestring wordtospan = new spannablestring(title);

int start = title.indexof(searchkeys);

int end = start + searchkeys.length();

wordtospan.setspan(new foregroundcolorspan(color.red),

start, end, spanned.span_exclusive_exclusive);

holder.producttitle.settext(wordtospan);

其中的title是標題,searchkeys是搜尋關鍵字,在foregroundcolor中,可以指定顯示的顏色,或者使用backgroundcolor設定背景顏色,方法都是類似的,如果是在listview中使用該方法,直接在adapter中設定即可。

Flutter 搜尋內容高亮顯示

flutter 搜尋內容高亮顯示方法 searchcontent 輸入的搜尋內容 textcontent 需要顯示的文字內容 frontcontent 需要另外新增在最前面的文字 fontsize 需要顯示的字型大小 fontcolor 需要顯示的正常字型顏色 selectfontcolor 需要顯...

android 高亮顯示指定區域

國際慣例 首先熟悉兩點概念 聽著是不是感覺有點一樣,二者在window佔據全部screen時,返回值相等 不同的典型情況是在dialog中時。當dialog出現在螢幕中間時,view.getlocationonscreen 取得的值要比 view.getlocationinwindow 取得的值要大...

ArcGIS AO開發高亮顯示某些要素

參考 1 ifeaturecursor pcur ifeatureclass.search iqueryfilter pfilter pfilter.whereclause straddress 輸入查詢條件,也就是你寸位址的欄位名 didian ifeature pfeat pcur.nextfe...