搜尋功能,關鍵字高亮顯示

2021-08-27 20:57:41 字數 1153 閱讀 6917

**如下,直接呼叫即可:

/**

* 搜尋關鍵字高亮

*@param view

*@param value

*@param keys 由key.spilt(" ") 分割獲得

*@param context

*/public

static

void

setuptextview(textview view, final string value, string keys, context context)

final spannablestringbuilder builder = new spannablestringbuilder(value);

// 先將所有需要高亮的索引置為1

final

int array = new

int[value.length()];

for (int i = 0; i < array.length; i++)

array[i] = 0;

for (string key : keys)

int s = value.indexof(key);

int e = s + key.length();

if (e <= value.length() && s >= 0) }}

// 根據上面結果,合併索引

int index = 0;

while (index < array.length)

final

int s = index;

while (index < array.length && array[index] == 1)

final

int e = index;

//設定關鍵字顏色 #fb5b5e

final foregroundcolorspan span = new foregroundcolorspan(context.getresources().getcolor(r.color.red_checked));

builder.setspan(span, s, e, spannable.span_inclusive_exclusive);

}view.settext(builder);

}

WPF搜尋關鍵字高亮顯示

目標 在wpf中,對lucene.net進行全文檢索後的結果中包含的關鍵字進行高亮顯示。檢索結果中的關鍵字高亮顯示,在網頁中顯示是很簡單的,lucene中加標籤樣式就可以了,可是在wpf中就不行了。我在wpf中用gridcontrol顯示搜尋結果列表,gridcontrol的模板裡用textbloc...

高亮顯示關鍵字例項 替換搜尋關鍵字例項

票房第一的審死官,主演 周星馳,梅艷芳票房第二的家有喜事,主演 周星馳,張國榮票房第三的鹿鼎記,主演 周星馳,林青霞票房第四的武狀元蘇乞兒,主演 周星馳,張敏票房第五的鹿鼎記2,主演 周星馳,林青霞 在這一年,香港電影票房前五的作品都由周星馳主演。而在之後周星馳的導演歲月裡,票房也是一度創造了神話。...

如何高亮顯示關鍵字

以前寫全文檢索程式的時候寫的.原創 by 飛鳥 dev club.com email flybird dev club.com ie5.5 指令碼引擎 required dim patern dim found dim str dim result patern a b str a dog fall...