Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SearchView remove blue focus line and show cursor at certain position

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.

like image 309
luckysing_noobster Avatar asked Nov 20 '13 01:11

luckysing_noobster


2 Answers

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

like image 149
luckysing_noobster Avatar answered Oct 04 '22 01:10

luckysing_noobster


You can use

android:queryBackground="@android:color/transparent"
like image 35
Kshitij Jain Avatar answered Oct 03 '22 23:10

Kshitij Jain