search view

This commit is contained in:
Thomas 2020-12-07 14:55:11 +01:00
parent 85097ce51b
commit 5ec97f3f81
3 changed files with 10 additions and 6 deletions

View File

@ -2,7 +2,7 @@
<resources>
<color name="colorPrimary">#684971</color>
<color name="colorPrimaryDark">#3d2b43</color>
<color name="colorAccent">#684971</color>
<color name="colorAccent">#3d2b43</color>
<color name="colorGreen">#6fc384</color>
<color name="colorLightRed">#e46772</color>

View File

@ -180,21 +180,25 @@ public class MainActivity extends AppCompatActivity {
toolbarMenu = menu;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
searchView = (SearchView) menu.findItem(R.id.action_filter).getActionView();
searchView.setIconifiedByDefault(false);
MenuItem actionFilterItem = menu.findItem(R.id.action_filter);
searchView = (SearchView) actionFilterItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
HomeFragment home = (HomeFragment) fragments.get(0);
home.filter(query);
return true;
if (!searchView.isIconified()) {
searchView.setIconified(true);
}
menu.findItem(R.id.action_filter).collapseActionView();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
HomeFragment home = (HomeFragment) fragments.get(0);
home.filter(newText);
return true;
return false;
}
});

View File

@ -6,7 +6,7 @@
android:icon="@drawable/ic_search"
android:title="@string/menu_action_filter"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
app:showAsAction="always|collapseActionView" />
<item
android:id="@+id/action_settings"
android:icon="@drawable/ic_settings"