14

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
luckysing_noobster
  • 1,933
  • 5
  • 24
  • 50
  • `android:background = @android:color/transparent`. This will remove the blue line – Rahul Gupta Nov 20 '13 at 02:17
  • I tried doing that but the blue line does not disappear.The background property just sets the the background of the Searchview to transparent and does not remove the focus line. – luckysing_noobster Nov 21 '13 at 07:13

3 Answers3

28

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

luckysing_noobster
  • 1,933
  • 5
  • 24
  • 50
2

You can use

android:queryBackground="@android:color/transparent"
Kshitij Jain
  • 2,103
  • 2
  • 13
  • 18
0

I was able to make it work by clearingfocus on the search edit text during the menu creation function. Code below:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        ...

        final MenuItem searchItem = menu.findItem(R.id.action_search);

        if (searchItem != null) {
            // Associate searchable configuration with the SearchView
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            final SearchView view = (SearchView) searchItem.getActionView();
            if(view !=null){
                LinearLayout searchPlate = (LinearLayout)mSearchView.findViewById(R.id.search_plate);
                if(searchPlate != null){
                    mSearchEditText = (EditText)searchPlate.findViewById(R.id.search_src_text);
                    if(mSearchEditText != null){
                        mSearchEditText.clearFocus();     // This fixes the keyboard from popping up each time
                    }
                }
            }
        }
}
falc0nit3
  • 999
  • 2
  • 8
  • 16