VIN
VIN

Reputation: 6947

SearchView not showing queryHint text

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.

Upvotes: 3

Views: 10426

Answers (6)

Cedriga
Cedriga

Reputation: 4156

In the xml layout file just add

app:iconifiedByDefault="false"

Notice that it's app: and not android:

Upvotes: 6

Selmeny
Selmeny

Reputation: 220

For android.support.v7.widget.SearchView, instead of using

android:queryHint="your hint" 
android:iconifiedByDefault="false"

you must use

app:queryHint="your hint" 
app:iconifiedByDefault="false"

Upvotes: 7

leodev
leodev

Reputation: 228

In the xml layout file just add

app:queryHint="My hint"

Upvotes: 3

James Chang
James Chang

Reputation: 632

In the XML, add android:iconifiedByDefault="false" if you have already set a value for android:queryHint.

Upvotes: 7

searchView.setIconified(false);

Upvotes: 12

VIN
VIN

Reputation: 6947

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()));

Upvotes: 4

Related Questions