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

Android searchView,显示长字符串的第一部分而不是最后一部分,android,searchview,Android,Searchview,如果将SearchView查询设置为比框长的字符串,如何使其成为字符串的第一部分而不是最后一部分可见?(我将其用作网络视图的导航/搜索栏。) 我知道 并希望它显示出来 Start of long 而不是 at the end 它总是告诉我结局。一、 本质上,我们希望它能滚动回到文本的开头 编辑:我确实希望完整的文本出现在那里,只需滚动到开头。基于此,我会尝试这样做 mySearchView.setOnFocusChangeListener(new OnFocusChangeListener(

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

我知道

并希望它显示出来

Start of long
而不是

at the end
它总是告诉我结局。一、 本质上,我们希望它能滚动回到文本的开头

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

基于此,我会尝试这样做

mySearchView.setOnFocusChangeListener(new OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus == false) {  // lost focus
   mEdittext.setSelection(0,0);
}
}
});

另外,请检查此项,否则如果我记得很清楚,我将无法帮助您,您需要在
搜索视图中找到
编辑文本
,然后在其上设置省略号

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);

上述解决方案对我不起作用。 我使用的是appcompat v7操作栏,这很有效

EditText editText = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
editText.setSelection(0);

SearchView没有setSelection功能,但感谢您的尝试!很抱歉,我只搜索了searchviews是否设置了setonfocuschangelister,我假设它会有一个setSelection。尝试将android:ellipsize=“start”添加到布局文件中的searchview中我确实希望所有文本都在框中,只需滚动以显示开头,第二组代码工作正常,谢谢!我确实编辑了您的答案以更正searchView。查找。。。到mySearchView。查找…我得到一个NullPointerException。EditText为空
EditText editText = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
editText.setSelection(0);