【问题标题】:Altering Search Dialog更改搜索对话框
【发布时间】:2011-09-03 12:43:16
【问题描述】:

是否可以更改我的 Activity 上的搜索对话框(Android 3.0 之前的版本)?这是按下硬件搜索按钮时下拉的搜索栏。通过改变,我的意思是修改布局。如果可以的话,我想添加一个额外的按钮。

【问题讨论】:

  • 问题here 看起来像您需要的。看来要走的路是在你的activity中拦截onSearchRequested,创建你自己的界面。
  • 你可以轻松做到。在这里查看答案:stackoverflow.com/a/44131089/3649347

标签: android search


【解决方案1】:

我觉得浮动搜索框是你想要的~ 不难,就是配置有点复杂~ 首先你需要配置搜索栏的参数 像这样新建一个 searchable.xml 配置文件:

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

  <!-- label is the text at the bottom of the search bar,hint is the text in the search bar -->
    android:label="@string/search_label"
    android:hint="@string/search_hint" 
    android:searchMode="showSearchLabelAsBadge"

  <!-- voice search -->
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:voiceLanguageModel="free_form"
    android:voicePromptText="@string/search_invoke"


    <!-- Configure search suggestions-->

   android:searchSuggestAuthority="com.android.cbin.SearchSuggestionSampleProvider"
    android:searchSuggestSelection=" ? "
/>

您应该在 mainfest.xml 中执行此操作:

<activity android:name="SearchResultActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH"></action>
</intent-filter>

     
<!-- searchable.xml -->

<meta-data android:resource="@xml/searchable"

   android:name="android.app.searchable"></meta-data>

</activity>
<!-- For each Activity can use search bar,
 be sure to start the label into the Activity 
in which the value is the search results-->
<meta-data android:name="android.app.default_searchable"
     android:value=".SearchResultActivity"
/>

<provider android:name="SearchSuggestionSampleProvider"

android:authorities="com.android.cbin.SearchSuggestionSampleProvider"></provider>

然后重写Activity的onSearchRequested函数

差不多这样,细节忘了~。~!!!

祝你好运~

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2012-12-05
    相关资源
    最近更新 更多