SearchView删除蓝色焦点线并在某个位置显示光标

luc*_*ter 14 android focus autocompletetextview searchview android-background

我一直在尝试删除SearchView中的蓝色焦点线.我将它投射到AutoCompleteTextView,以便我可以为searchView使用自定义图标.

    int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    searchtextView = (AutoCompleteTextView) searchView.findViewById(id); 
Run Code Online (Sandbox Code Playgroud)

我试过用

searchtextView.setBackGroundColor(0) 
Run Code Online (Sandbox Code Playgroud)

并在我的xml中手动将背景设置为#0000000,但我仍然可以看到底部的蓝线.

我面临的第二个问题是光标最初没有显示在文本上.我想在searchview中没有输入任何内容时显示光标.我试图通过编程方式进行操作

if (searchtextView.getText().toString().length() >= 0) {
   searchtextView.setSelection(searchtextView.getText().toString().length());
 }
Run Code Online (Sandbox Code Playgroud)

即使在searchView内部没有文本也应该显示光标.我认为它与焦点有关,因为当我输入2-3个字符时,光标会自动显示.

luc*_*ter 28

我能够通过设置默认搜索视图板的背景来解决它,如下所示

int searchPlateId = searchView.getContext().getResources()
            .getIdentifier("android:id/search_plate", null, null);
    View searchPlateView = searchView.findViewById(searchPlateId);
    if (searchPlateView != null) {
        searchPlateView.setBackgroundColor(Color.BLACK);
    }
Run Code Online (Sandbox Code Playgroud)

这篇文章有帮助.文章链接