如何在操作栏中实施youtube应用,例如搜索功能,如何从服务器动态搜索字符串并在列表视图中显示。我不知道如何在其中添加动态搜索功能,这是服务器的响应。
Step-1
如果您对搜索结果有更多需求,则必须对服务器实施onTextChange调用,并作为文本更改实现retrieve << [list。
或如果您有
小列表
,则可以检索活动的整个列表正在启动。Step-2
在AutoCompleteTextView
的适配器中设置数据。MaterialSearchView searchView = (MaterialSearchView) findViewById(R.id.search_view);
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//Do some magic
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
//Do some magic
return false;
}
});
searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
@Override
public void onSearchViewShown() {
//Do some magic
}
@Override
public void onSearchViewClosed() {
//Do some magic
}
});
代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search: {
mSearchView.show(true/false); // animate, ONLY FOR MENU ITEM
return true;
}
default:
return super.onOptionsItemSelected(item);
}
}
XML:
<com.lapism.searchview.SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="match_parent" />
样式SearchView:
<attr name="search_version" format="enum"> <enum name="toolbar" value="1000" /> <enum name="menu_item" value="1001" /> </attr> <attr name="search_version_margins" format="enum"> <enum name="toolbar_small" value="2000" /> <enum name="toolbar_big" value="2001" /> <enum name="menu_item" value="2002" /> </attr> <attr name="search_theme" format="enum"> <enum name="light" value="3000" /> <enum name="dark" value="3001" /> </attr> <attr name="search_icon_color" format="color" /> <attr name="search_background_color" format="color" /> <attr name="search_text" format="string" /> <attr name="search_text_color" format="color" /> <attr name="search_text_size" format="dimension" /> <attr name="search_hint" format="string" /> <attr name="search_hint_color" format="color" /> <attr name="search_divider" format="boolean" /> <attr name="search_voice" format="boolean" /> <attr name="search_voice_text" format="string" /> <attr name="search_animation_duration" format="integer" /> <attr name="search_shadow" format="boolean" /> <attr name="search_shadow_color" format="boolean" /> <attr name="search_elevation" format="dimension" />