我正在开发android应用程序并在androidx的帮助下进行设计。我把SearchView放到工具栏,我想通过点击ToolBar上的任何点,searchView将被激活(目前,只有通过点击它激活的搜索栏的图标。这是我在activity_main XML文件中的代码
I want that by clicking any ToolBar point, SearchView to activate and let user enter the text
<androidx.appcompat.widget.Toolbar
        android:id="@+id/tool_bar_id"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_margin="20dp"
        android:layout_marginTop="40dp"
        android:background="@drawable/circle"
        android:elevation="5dp"
        app:layout_constraintCircleRadius="100dp"
        app:layout_constraintTop_toTopOf="parent">
        <androidx.appcompat.widget.SearchView
            android:id="@+id/search_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp" />
    </androidx.appcompat.widget.Toolbar>发布于 2019-09-19 06:24:15
你可以通过代码来完成,将clicklistener添加到工具栏中
Toolbar toolbar=findViewById(R.id.tool_bar_id);
        SearchView searchView=findViewById(R.id.search_id);
        toolbar.setOnClickListener(v -> {
            searchView.setIconified(false);
        });https://stackoverflow.com/questions/58001240
复制相似问题