noname
noname

Reputation: 177

Search Widget in action bar not displaying the default text

Hi the search widget in the action bar of my application is not displaying the default text for some reason. I am sure I might be missing something. The code looks like below:-

 @Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    try{
        SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
        searchView.setOnQueryTextListener(this);
        }catch(Exception e){
            Log.v(TAG,"inflated"+e.getMessage()+"--"+e.getClass()+"-"+e.getClass());
        }
    return true;
}

menu/activity_main

<menu xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:id="@+id/action_search"
      android:title="@string/search_title"
      android:icon="@android:drawable/ic_menu_search"
      android:showAsAction="ifRoom|collapseActionView"
      android:actionViewClass="android.widget.SearchView" />
 </menu>

values/strings.xml

<resources>
<string name="search_title">Search Data</string>
</resources>

The search widget is working perfectly , the only thing is the default text "Search Data" is not showing.. Can someone tell me what am I doing wrong

Upvotes: 3

Views: 2659

Answers (1)

Georgy Gobozov
Georgy Gobozov

Reputation: 13721

Try to use this

searchView.setQueryHint(getResources().getString(R.string.search_title));

Upvotes: 5

Related Questions