SearchView删除蓝色的对焦线,并在某个位置显示光标 [英] SearchView remove blue focus line and show cursor at certain position

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

问题描述

我一直试图删除SearchView中的蓝色焦点行。我将它转换为AutoCompleteTextView,以便我可以使用自定义图标作为我的searchView。

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

我试过使用

  searchtextView.setBackGroundColor(0)

手动设置背景为#0000000在我的XML,但我仍然可以看到底部的蓝线。

我面临的第二个问题是光标最初不显示在文本上。当searchview中没有输入任何内容时,想要显示光标。我尝试以编程方式使用

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

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

解决方案

可以通过设置默认的searchview板的背景来解决这个问题。

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

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

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

I have tried using

searchtextView.setBackGroundColor(0) 

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

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.

解决方案

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

This article helped.article link

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

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