Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在工具栏支持操作栏中设置搜索不会';为什么不工作?_Java_Android - Fatal编程技术网

Java 在工具栏支持操作栏中设置搜索不会';为什么不工作?

Java 在工具栏支持操作栏中设置搜索不会';为什么不工作?,java,android,Java,Android,我一直在尝试为我的应用添加/创建搜索功能!所以在通过android文档之后,就有了如何做到这一点的培训!我添加了它,因为它解释了,但它不工作,当我点击搜索图标,它没有反应,我甚至不能把任何文本进行搜索!我使用的是支持版本25 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" x

我一直在尝试为我的应用添加/创建搜索功能!所以在通过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>

尝试使用查询侦听器。它检测在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;
                }
            });

经过一番努力,我意识到错误是由于在协调器布局中包装视图造成的。因此,工具栏的点击感觉不到它被它之后添加的其他视图占用。所以我可以更改布局属性,但我决定改用相对布局

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto">

            <include layout="@layout/toolbar"/>

            <FrameLayout
                android:id="@+id/contentContainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/bottom_bar" />

            <com.roughike.bottombar.BottomBar
                android:id="@+id/bottom_bar"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_gravity="bottom"
                android:layout_alignParentBottom="true"
                app:bb_tabXmlResource="@xml/bottom_bar_tabs" />

    </RelativeLayout> 

它不工作!问题是,我无法向输入字段添加任何信息/文本/文字,因为输入字段没有显示在图标单击或触摸上!QueryListener!