Android SearchView Extended Default Suite

I am currently developing simple applications with Android Studio with a minimum API level of 8, now I use android.support.v7.widget.SearchView in the LinearLayout layout in content_main.xml and not in ACTIONBAR , now the problem is I canโ€™t install searchView as Expanded by default, I'm already looking for a solution, and I only got this:

android:iconifiedByDefault="false"

here is my complete code for my search.

  <android.support.v7.widget.SearchView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/searchView" android:background="#00000000" android:iconifiedByDefault="false" android:layout_weight="1" /> 

but no luck, it does not work. can anyone help me? Any help would be greatly appreciated. Thank you very much!

+5
source share
3 answers

Ok, so I will solve the problem. to anyone who wants to use the support library for SearchView here, how you can configure it.

  <android.support.v7.widget.SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="wrap_content" app:closeIcon="@drawable/ic_clear" // To set custom clear icon app:searchIcon="@drawable/ic_search" //To set custom search icon app:queryBackground="@color/transparent" // i decided to remove underline so i create a custom background for my searchView app:queryHint="@string/filterHint" //to set a custom Hint app:iconifiedByDefault="false" //And finally, to Expand it as default /> 

as I said, I'm afraid to override the xml layout at runtime via java code, so that it is organized and no more overridden at runtime, this is how I do it.

Link

Thanks for the help!!!

+11
source

I used the code below to expand the search and place the cursor at the same time:

 final SearchView sv = new SearchView(((MainActivity) getActivity()).getSupportActionBar().getThemedContext()); sv.setIconifiedByDefault(true); sv.setFocusable(true); sv.setIconified(false); sv.clearFocus(); sv.requestFocusFromTouch(); 
+3
source

To make SearchView extended by default, call setIconifiedByDefault (false) on it when you initialize it (for example, onCreate (..)). I found that in most cases this will automatically focus, but if not just call requestFocus () too.

+1
source

Source: https://habr.com/ru/post/1236152/


All Articles