SearchView 移除蓝色焦点线并在特定位置显示光标 [英] SearchView remove blue focus line and show cursor at certain position

查看:29
本文介绍了SearchView 移除蓝色焦点线并在特定位置显示光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been trying to remove the blue focus line in the SearchView .I am casting it to a AutoCompleteTextView so that I can use customized icons for my searchView.

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

我试过使用

searchtextView.setBackGroundColor(0) 

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

and manually setting the background to #0000000 in my xml but I can still seee the blue line at the bottom.

我面临的第二个问题是光标最初没有显示在文本上.我想在搜索视图中没有输入任何内容时显示光标.我尝试使用

The second problem I am facing is that the cursor does not show up on the text initially.I want to display the cursor when nothing is entered in the searchview.I tried to do it programmatically by using

if (searchtextView.getText().toString().length() >= 0) {
   searchtextView.setSelection(searchtextView.getText().toString().length());
 }

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

which should display the cursor even when no text exist inside the searchView.I think it has something to do with the focus because when I type in 2-3 characters the cursor shows up automatically.

推荐答案

我可以通过如下设置默认searchview板块的背景来解决

I was able to solve it by setting the background of the default searchview plate as follows

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

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

这篇关于SearchView 移除蓝色焦点线并在特定位置显示光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆