gpt4 book ai didi

Android searchView,显示长字符串的第一部分而不是最后一部分

转载 作者:行者123 更新时间:2023-11-29 19:02:33 26 4
gpt4 key购买 nike

如果我将 SearchView 查询设置为比框长的字符串,我该如何使它是可见的字符串的第一部分而不是最后一部分? (我将其用作 WebView 的导航/搜索栏。)

我愿意

mySearchView.setQuery("Start of long string.... at the end.", false);

并希望它显示

Start of long

代替

at the end

它总是告诉我结局。本质上,我希望它滚动回到文本的开头。

编辑:我确实希望完整的文本在那里,只是滚动到开头。

最佳答案

如果我没记错的话,您需要获取 SearchView 中的 EditText,然后在其上设置椭圆大小。

int id = mySearchView.getContext()
.getResources()
.getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) mySearchView.findViewById(id);
editText.setEllipsize(TextUtils.TruncateAt.END);

如果您不想椭圆化,您可以使用相同的方法并在 EditText 中设置位置。

int id = mySearchView.getContext()
.getResources()
.getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) mySearchView.findViewById(id);
editText.setSelection(0);

关于Android searchView,显示长字符串的第一部分而不是最后一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48470291/

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