I have a search view with a background drawable, but I can't seem to get the text to appear no matter what I try. No text shows up in the SearchView.
I've tried the android:text
and android:queryHint
and even setting it programmatically using mSearchView.setQueryHintText("search for something");
but none of these work. The searchView is not inside an actionBar.
Here is the xml for the searchview
<android.support.v7.widget.SearchView
android:id="@+id/m_search_view"
android:layout_width="match_parent"
android:layout_height="@dimen/searchbar_height"
android:layout_alignWithParentIfMissing="true"
android:layout_toLeftOf="@+id/other_button"
android:background="@drawable/rounded_corner_box"
android:focusableInTouchMode="true"
android:gravity="center_vertical|left"
android:paddingLeft="@dimen/left_padding"
android:queryHint="search for something"
android:textAppearance="@style/m_text_appearance"
android:textColor="@color/m_text_color" />
When I don't set a background, I don't see the searchView at all (the searchView is translucent).
Any help would be appreciated.
Fixed my own issue: I had to dig into the SearchView's source. This is how I got the background and text to show in the searchView:
SearchView searchView = (SearchView)mLayout.findViewById(R.id.m_searchview);
searchView.setQueryHint("search for something");
View searchTextView = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchTextView.setBackground(
ResourcesCompat.getDrawable(getResources(), R.drawable. rounded_corner_box, getTheme()));
View searchFrame = searchView.findViewById(android.support.v7.appcompat.R.id.search_edit_frame);
searchFrame.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.m_background, getTheme()));