Android實現帶搜索建議的浮動搜索框:Floating Search View
實現帶搜索建議的浮動搜索框。
用法
- In your dependencies, addcompile 'com.github.arimorty:floatingsearchview:1.0.1'
- Add a FloatingSearchView to your view hierarchy, and make sure that it takes up the full width and height of the screen
- Listen to query changes and provide suggestion items that implement SearchSuggestion
示例:
<com.arlib.floatingsearchview.FloatingSearchView android:id="@+id/floating_search_view" android:layout_width="match_parent" android:layout_height="match_parent" app:floatingSearch_searchBarMarginLeft="@dimen/search_view_inset" app:floatingSearch_searchBarMarginTop="@dimen/search_view_inset" app:floatingSearch_searchBarMarginRight="@dimen/search_view_inset" app:floatingSearch_showMenuAction="true" app:floatingSearch_searchHint="Search..." app:floatingSearch_voiceRecHint="Say something..." app:floatingSearch_showSearchHintWhenNotFocused="true" app:floatingSearch_showVoiceInput="true" app:floatingSearch_showOverFlowMenu="true" app:floatingSearch_hideOverflowMenuWhenFocused="true" app:floatingSearch_showSearchKey="false" app:floatingSearch_dismissOnOutsideTouch="true" app:floatingSearch_menu="@menu/menu_main"/>
mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override public void onSearchTextChanged(String oldQuery, final String newQuery) { //get suggestions based on newQuery //pass them on to the search view mSearchView.swapSuggestions(newSuggestions); } });
Configure overflow menu:
In your xml, add menu resource
app:floatingSearch_menu="@menu/menu_main"
Listen for item selections
mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() { @Override public void onMenuItemSelected(MenuItem item) { } });
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!