This commit is contained in:
Nikhil Peter Raj 2014-03-08 15:28:46 +05:30
parent 0a0bdad5b5
commit b29c430959
2 changed files with 14 additions and 3 deletions

View File

@ -353,12 +353,23 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
// Get the searchview
MenuItem searchItem = menu.findItem(R.id.menu_key_list_public_search);
final MenuItem searchItem = menu.findItem(R.id.menu_key_list_public_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
// Execute this when searching
mSearchView.setOnQueryTextListener(this);
//Collapse the SearchView if it does not have focus
mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
MenuItemCompat.collapseActionView(searchItem);
}
}
});
super.onCreateOptionsMenu(menu, inflater);
}

View File

@ -4,7 +4,7 @@
<item
android:id="@+id/menu_key_list_public_import"
app:showAsAction="always|withText"
app:showAsAction="ifRoom|withText"
android:icon="@drawable/ic_action_add_person"
android:title="@string/menu_import" />
<item
@ -16,5 +16,5 @@
android:title="@string/menu_search"
android:icon="@drawable/ic_action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom" />
app:showAsAction="collapseActionView|ifRoom" />
</menu>