我有一个搜索框设置,通过ContentProvider提供自定义搜索建议.这些建议通过Android搜索建议API处理,通过调用Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)方法收集.当在光标中返回建议时,它们将显示在搜索框下方的列表中.
我的问题是我想在每个搜索建议粗体中创建一个子字符串.我已经把HTML粗体标记<b>,并</b>围绕这些子.但是,即使通过添加Html.fromHtml(stringWithBoldTags)返回的光标(a MatrixCursor),文本也都显示为纯文本.
我想知道是否有一种方法只是使用搜索建议API使一些文本变粗.我不想完全重新设置搜索建议,所以在这个小小的变化中实现我自己的搜索建议API似乎是最重要的.
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
List<String> suggestions = getSuggestions(searchTerm);
MatrixCursor cursor = new MatrixCursor(new String[] { BaseColumns._ID,
SearchManager.SUGGEST_COLUMN_TEXT_1,
SearchManager.SUGGEST_COLUMN_INTENT_DATA,
SearchManager.SUGGEST_COLUMN_QUERY } );
for (int i = 0; i < suggestions.size(); ++i) {
String suggestion = suggestions.get(i);
Object[] row = { Integer.toString(i),
Html.fromHtml(makeSubstringBold(suggestion, searchTerm)),
suggestion, suggestion };
cursor.addRow(row);
}
return cursor;
}
private List<String> getSuggestions(String searchTerm) {
// Return a list of suggestions for the searchTerm
}
private String makeSubstringBold(String fullString, String substring) {
// Find substring in fullString and add HTML bold tags either side of it
}
Run Code Online (Sandbox Code Playgroud)
如果有人知道你可以使搜索建议API服从光标中返回的粗体标签,那么我将非常感激!
| 归档时间: |
|
| 查看次数: |
507 次 |
| 最近记录: |