[英]Android - force searchview to open programmatically
In my application am using the library for the autoComplete searchview Here is what the library am using在我的应用程序中,我将库用于 autoComplete searchview 这是库正在使用的内容
compile 'com.miguelcatalan:materialsearchview:1.4.0'
Here is my xml这是我的 xml
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/theme_primary" />
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
What I want is I want to open the searchView programmatically to open searchbar without using pressing the search icon in actionbar
.我想要的是我想以编程方式打开 searchView 以打开搜索
actionbar
而无需按下actionbar
的搜索图标。 How can i achieve this.any help.我怎样才能做到这一点。任何帮助。
您可以使用该库必须扩展的 autocompletetextview 的内置功能
search_view.setFocusedByDefault(true);
I observed the library and MaterialSearchView class i see there one method it is showSearch().我观察了库和 MaterialSearchView 类,我看到有一种方法是 showSearch()。 may be it is for show SearchView.
可能是为了显示 SearchView。
method is in MaterialSearchView.class方法在 MaterialSearchView.class 中
public void showSearch(boolean animate) {
if (isSearchOpen()) {
return;
}
So you can call this method like this :所以你可以像这样调用这个方法:
materialSearchView.showSearch(true/false);
May be work for your requirement.可能适合您的要求。 Hope this help you.
希望这对你有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.