- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在我的项目中使用 Google Maps API v2 Android,我在其中使用 PlaceAutocomplete Predictions API 来获取建议。我的问题是如何使建议看起来更动态,即当用户输入时,建议中与所提供的输入相匹配的字母应该改变颜色,类似于谷歌地图,如下所示(这里的字母“n”、“e”和'w' 在建议中加粗):
getFullText(CharacterStyle matchStyle)
returns the full text of a place description. This is a combination of the primary and secondary text. Example: "Eiffel Tower, Avenue Anatole France, Paris, France". In addition, this method lets you highlight the sections of the description that match the search with a style of your choice, usingCharacterStyle
. The CharacterStyle parameter is optional. Set it to null if you don't need any highlighting.
但是我在文档中找不到关于如何使用 getFullText(CharacterStyle)
实现 CharacterStyle
的进一步解释,请帮忙。提前致谢! :)
最佳答案
private static final CharacterStyle STYLE_BOLD = new StyleSpan(Typeface.BOLD);
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
// Sets the primary and secondary text for a row.
// Note that getPrimaryText() and getSecondaryText() return a CharSequence that may contain
// styling based on the given CharacterStyle.
AutocompletePrediction item = getItem(position);
TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
textView1.setText(item.getPrimaryText(STYLE_BOLD));
textView2.setText(item.getSecondaryText(STYLE_BOLD));
return row;
}
关于android - 如何在 google maps API for android 中为自动完成预测添加样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41915304/
我是一名优秀的程序员,十分优秀!