Issue
I have a search view and I have a query hint attribute. However the hint appears only after clicking on the search view. Is there a way to make it appear before it has been clicked?
<SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView4"
android:layout_marginBottom="14dp"
android:layout_marginTop="30dp"
android:queryHint="Search" />
I have seen another SO question with a similar query, but it wasn't solved. That's why I am asking again.
Solution
You can add these below lines:
SearchView searchView = (SearchView) findViewById(R.id.searchView);
searchView.onActionViewExpanded();
searchView.setIconified(true);
and add this to hiding focus (Keyboard)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
search.clearFocus();
}
}, 300);
Answered By - Selim YILDIZ


0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.