gpt4 book ai didi

android - 如何在 google maps API for android 中为自动完成预测添加样式?

转载 作者:搜寻专家 更新时间:2023-11-01 09:37:36 25 4
gpt4 key购买 nike

我在我的项目中使用 Google Maps API v2 Android,我在其中使用 PlaceAutocomplete Predictions API 来获取建议。我的问题是如何使建议看起来更动态,即当用户输入时,建议中与所提供的输入相匹配的字母应该改变颜色,类似于谷歌地图,如下所示(这里的字母“n”、“e”和'w' 在建议中加粗):

enter image description here

我已阅读文档 onetwo ,它说:

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, using CharacterStyle. 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com