search view
This commit is contained in:
parent
85097ce51b
commit
5ec97f3f81
|
@ -2,7 +2,7 @@
|
||||||
<resources>
|
<resources>
|
||||||
<color name="colorPrimary">#684971</color>
|
<color name="colorPrimary">#684971</color>
|
||||||
<color name="colorPrimaryDark">#3d2b43</color>
|
<color name="colorPrimaryDark">#3d2b43</color>
|
||||||
<color name="colorAccent">#684971</color>
|
<color name="colorAccent">#3d2b43</color>
|
||||||
|
|
||||||
<color name="colorGreen">#6fc384</color>
|
<color name="colorGreen">#6fc384</color>
|
||||||
<color name="colorLightRed">#e46772</color>
|
<color name="colorLightRed">#e46772</color>
|
||||||
|
|
|
@ -180,21 +180,25 @@ public class MainActivity extends AppCompatActivity {
|
||||||
toolbarMenu = menu;
|
toolbarMenu = menu;
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.main, menu);
|
inflater.inflate(R.menu.main, menu);
|
||||||
searchView = (SearchView) menu.findItem(R.id.action_filter).getActionView();
|
MenuItem actionFilterItem = menu.findItem(R.id.action_filter);
|
||||||
searchView.setIconifiedByDefault(false);
|
searchView = (SearchView) actionFilterItem.getActionView();
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
HomeFragment home = (HomeFragment) fragments.get(0);
|
HomeFragment home = (HomeFragment) fragments.get(0);
|
||||||
home.filter(query);
|
home.filter(query);
|
||||||
return true;
|
if (!searchView.isIconified()) {
|
||||||
|
searchView.setIconified(true);
|
||||||
|
}
|
||||||
|
menu.findItem(R.id.action_filter).collapseActionView();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String newText) {
|
public boolean onQueryTextChange(String newText) {
|
||||||
HomeFragment home = (HomeFragment) fragments.get(0);
|
HomeFragment home = (HomeFragment) fragments.get(0);
|
||||||
home.filter(newText);
|
home.filter(newText);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
android:icon="@drawable/ic_search"
|
android:icon="@drawable/ic_search"
|
||||||
android:title="@string/menu_action_filter"
|
android:title="@string/menu_action_filter"
|
||||||
app:actionViewClass="android.widget.SearchView"
|
app:actionViewClass="android.widget.SearchView"
|
||||||
app:showAsAction="ifRoom|collapseActionView" />
|
app:showAsAction="always|collapseActionView" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_settings"
|
android:id="@+id/action_settings"
|
||||||
android:icon="@drawable/ic_settings"
|
android:icon="@drawable/ic_settings"
|
||||||
|
|
Loading…
Reference in New Issue