I try to expand and focus the search view programmatically in Fragment. But it was not expanded. I refer the internet and try so many time But it was not expanded. But same time searchView expanded in activity. below code was I used.

@Override
       public void onViewCreated(@NonNull View view, @Nullable Bundle  savedInstanceState) {
       super.onViewCreated(view, savedInstanceState);

     SearchView searchView = view.findViewById(R.id.search);
     searchView.setIconified(true);
     searchView.requestFocus();
}

I expect Once I show the fragment, That fragment's search view should be focused.

1 Answers

0
Amine On

You can expand your SearchView with setIconified set to false

searchView.setIconified(false);

And collapsed with true

searchView.setIconified(true);