android XML下searchable.xml

   1: <?xml version="1.0" encoding="utf-8"?>

   2: <searchable xmlns:android="http://schemas.android.com/apk/res/android"

   3:     android:label="@string/search_label" 

   4:     android:hint="@string/search_hint"

   5:     android:searchSettingsDescription="@string/search_settings_description"

   6:     android:searchSuggestAuthority="searchprovider"

   7:     android:searchSuggestIntentAction="android.intent.action.SEARCH"

   8:     android:searchSuggestThreshold="1"

   9:     android:includeInGlobalSearch="true"

  10:     android:searchSuggestSelection=" ?"

  11:     >

  12: </searchable>


参数说明:
android:searchSuggestAuthorith
此属性的值就是SearchSuggestAuthorith中的AUTHORITH了。
android:searchSuggestIntentAction
此属性定义了当我们选中搜索提示的内容时发生的目的动作。
android:searchSuggestThreshold
此属性定义了至少输入几个字符时才会弹出提示
android:includeInGlobalSearch
是否将内容加入android的全局搜索。true,加入。
android:searchSuggestSelection
定义搜索时参数的占位符
 
PS:配置参数不止这些,可以自己看看android的参考手册。
 
3.配置AndroidManifest.xml
   1: <provider android:name=".SearchSuggestionsProvider" android:authorities="searchprovider" />
 
注意authorities的属性值哦。o(∩_∩)o

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,无法得知您所说的“搜索框”具体指的是哪一种。以下是两种可能的解答: 1. 在Android Studio中添加搜索框控件: 在XML布局文件中添加SearchView控件即可,如下所示: ```xml <SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="wrap_content" /> ``` 同时,还需要在Java代码中对SearchView进行初始化和设置监听器等操作,具体可参考以下代码: ```java SearchView searchView = findViewById(R.id.searchView); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { // 处理搜索提交事件 return false; } @Override public boolean onQueryTextChange(String newText) { // 处理搜索文本变化事件 return false; } }); ``` 2. 在Android Studio中添加搜索框功能: 如果您是想在Android应用中添加搜索功能,可以使用Android提供的Searchable Activity来实现。具体步骤如下: 1)在AndroidManifest.xml文件中添加Searchable配置: ```xml <activity android:name=".SearchableActivity"> <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> ``` 其中,SearchableActivity是您自己定义的Activity类名,@xml/searchable是一个XML文件,用于配置搜索框的属性。 2)在res/xml目录下创建searchable.xml文件,配置搜索框的属性,如下所示: ```xml <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/search_hint" android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" /> ``` 其中,label属性指定搜索框的标题,hint属性指定搜索框的提示文本,voiceSearchMode属性指定是否显示语音搜索按钮。 3)在SearchableActivity中处理搜索事件,如下所示: ```java public class SearchableActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_searchable); handleIntent(getIntent()); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); handleIntent(intent); } private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); // 处理搜索事件 } } } ``` 其中,handleIntent()方法用于处理搜索事件,可以在其中获取搜索关键字等信息,并进行相应的处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值