SearchView remove blue focus line and show cursor at certain position

前端 未结 3 970
旧时难觅i
旧时难觅i 2021-02-05 15:30

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.



        
3条回答
  •  情歌与酒
    2021-02-05 15:32

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

提交回复
热议问题