我一直在尝试为我的应用添加/创建搜索功能!因此,在通过Android文档后,有关于如何做到这一点的培训!我在解释时添加了它,但是当我点击搜索图标时它没有工作它没有响应,我甚至无法搜索任何文本!我使用的是25版支持。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/myScrollingContent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_bar" />
</android.support.v4.widget.NestedScrollView>
<com.roughike.bottombar.BottomBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
app:bb_tabXmlResource="@xml/bottombar_tabs_three"
app:bb_behavior="shy"/>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:1)
经过一番奋斗我意识到,错误是由于协调器布局中的视图包装造成的。因此,工具栏的点击不会被其他视图占用。所以我可以改变布局属性,但我决定使用相对布局。
paper-input
答案 1 :(得分:0)
尝试使用查询侦听器。它会检测在searchview中输入的任何内容
SearchView simpleSearchView = (SearchView) findViewById(R.id.simpleSearchView);
simpleSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//searchedInput will be the text that was entered
String searchedInput = query;
//Toast.makeText(MainActivity.this, query, Toast.LENGTH_SHORT).show();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});