如何在 Android Studio 中制作搜索框

How to make search box in Android Studio

我想在我的 android 应用程序中制作搜索框。我正在使用 Json 和 Retrofit 从我的 Wordpress 网站获取帖子,我希望用户可以按关键字对帖子进行排序,例如,如果他们搜索“love”,所有包含关键字 love 的帖子都会显示给他们,这就是方法我正在使用搜索方法:

https://wahstatus.com/wp-json/wp/v2/posts/?search=love&per_page=29

现在我想制作搜索框,当用户在框中插入关键字并按回车键时,url 应该自行更改..

像这样..

https://wahstatus.com/wp-json/wp/v2/posts/?search= keyword here  + &per_page=29

我不知道如何从搜索框插入关键字到url,请帮忙

我不希望工具栏中有搜索框,我希望它位于 activity..

您可以使用搜索视图

在xml

 <SearchView  
    android:id="@+id/searchView"  
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    android:queryHint="Search Here"  
    android:iconifiedByDefault="false"  
    android:layout_alignParentTop="true"  

/>

在Activity

 searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {  
        @Override  
        public boolean onQueryTextSubmit(String query) {  

             String searchText = query;       
             // Call the  api
         https://wahstatus.com/wp-json/wp/v2/posts/?search= searchText + &per_page=29

            }  
            return false;  
        }  

        @Override  
        public boolean onQueryTextChange(String newText) {  
         
            return false;  
        }  
    });