Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.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 Android-使用查询提示使整个搜索视图可单击_Java_Android_Searchview - Fatal编程技术网

Java Android-使用查询提示使整个搜索视图可单击

Java Android-使用查询提示使整个搜索视图可单击,java,android,searchview,Java,Android,Searchview,所以我一直在安卓工作室开发这个库存管理系统。在产品拍摄的片段中,我有一个搜索视图,我想让整个身体的搜索视图都可以点击。此问题的一部分已在此处解决:。但是我希望搜索视图有一个可见的查询提示。所以基本上我希望它是一个带有搜索图标和文本的按钮。我想要它,因为它应该打开一个对话框,用户实际上要在其中搜索产品。不在此搜索视图中。当我添加setIconified(true)时,可以单击整个主体,但查询提示不可见。像这样: 当我添加SetIconnified(false)时,查询提示可见,但只能单击搜索图标。

所以我一直在安卓工作室开发这个库存管理系统。在产品拍摄的片段中,我有一个搜索视图,我想让整个身体的搜索视图都可以点击。此问题的一部分已在此处解决:。但是我希望搜索视图有一个可见的查询提示。所以基本上我希望它是一个带有搜索图标和文本的按钮。我想要它,因为它应该打开一个对话框,用户实际上要在其中搜索产品。不在此搜索视图中。

当我添加setIconified(true)时,可以单击整个主体,但查询提示不可见。像这样:


当我添加SetIconnified(false)时,查询提示可见,但只能单击搜索图标。如下所示:

您可以在SearchView使用所有触摸之前拦截它们。我创建了一个简单的类来截获所有触摸事件。 科特林:

爪哇:

请参见xml的外观:

<com.example.testci.temp.TouchInterceptorLayout
            android:id="@+id/interceptorLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        <SearchView
                android:id="@+id/searchView"
                android:queryHint="@string/app_name"
                android:iconifiedByDefault="false"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"/>
</com.example.testci.temp.TouchInterceptorLayout>

现在您只需将
OnClickListener
设置为
interceptorLayout


您可以找到我的实验的完整代码。

我正在使用Java,对Kotlin一无所知,您有没有可能将TouchInterceptorLayout类更改为Java?@MertcanSeğmen我添加了TouchInterceptorLayout的Java版本。
public class TouchInterceptorLayout extends FrameLayout {
    public TouchInterceptorLayout(Context context) {
        super(context);
    }

    public TouchInterceptorLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TouchInterceptorLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
}
<com.example.testci.temp.TouchInterceptorLayout
            android:id="@+id/interceptorLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        <SearchView
                android:id="@+id/searchView"
                android:queryHint="@string/app_name"
                android:iconifiedByDefault="false"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"/>
</com.example.testci.temp.TouchInterceptorLayout>