이 포스팅은 Toolbar に 13行で SearchView を実装する 을 기본으로 번역하여 작성했습니다
제 일본어 실력으로 인하여 오역이나 오타가 발생할수 있습니다.
이런거 입니다.
ActionBar 에도 같은 요령으로 대응가능하다고 생각합니다.
onQueryTextSubmit, onQueryTextChange 설명은 이쪽
http://developer.android.com/reference/android/support/v7/widget/SearchView.OnQueryTextListener.html
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.search);
mSearchView = (SearchView) toolbar.getMenu().findItem(R.id.menu_search).getActionView();
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_search"
android:icon="@drawable/ic_menu_search"
android:title="@string/menu_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always" />
</menu>
Menu menu = toolbar.getMenu();
MenuItem item = menu.add("検索");
item.setIcon(R.drawable.ic_menu_search);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item.setActionView(mSearchView);
http://developer.android.com/reference/android/widget/SearchView.html#setIconified(boolean)
mSearchView.setIconfied(false);
http://developer.android.com/reference/android/view/ViewGroup.html#clearFocus()
mSearchView.clearFocus();
mSearchView.setQueryHint(“Hint”);
페이지 하단의 SearchView Widget 쪽
http://android-developers.blogspot.jp/2014/10/appcompat-v21-material-design-for-pre.html
comments powered by Disqus
Subscribe to this blog via RSS.