Android SearchView set Expanded by default

bernzkie picture bernzkie · Nov 17, 2015 · Viewed 17.4k times · Source

I'm currently developing a simple apps using Android Studio with the minimum API Level 8, now i currently using android.support.v7.widget.SearchView in my LinearLayout in content_main.xml layout, not on ACTIONBAR, now the problem is, i'm not able to set the searchView as Expanded by default, i already look for solution and i only got this:

android:iconifiedByDefault="false"

here is my full code for my searchView

          <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's not working. anyone could help me? any help would be appreciated. Thank you so much!

Answer

bernzkie picture bernzkie · Nov 17, 2015

Ok, so i solve the problem. to anyone who want to use support library for SearchView here's how you can customize 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 of overriding xml layout on runtime via java code, so to make it organize and no more overriding during the runtime, this is how i do it.

Reference

Thanks for help!!!