㈠ android 浮動搜索框如何使用
我從來沒用過,如果有人回答了,給我說一下
㈡ 安卓手機頂端搜索欄在哪裡找
咨詢記錄 · 回答於2021-10-19
㈢ 如何刪除android應用中的搜索框
需求:項目中的有關搜索的地方,加上清空文字的功能,目的是為了增加用戶體驗,使用戶刪除文本更加快捷
解決過程:開始的時候感覺這個東西不太好實現,主要就是布局的問題,可能是開始顧慮的太多了,再加上當時產品催的不太緊,而且這個功能也不是必須實現的。但是今天不一樣了,這個是老大讓加上的,說別的很多應用中都有這個功能,沒辦法那就加上唄,試著去使用了相對布局去實現,把一個刪除按鍵放在編輯框的右上方,當文字的時候就把刪除按鍵給顯示出來,當編輯框為空的時候就把刪除按鍵給隱藏掉。布局代碼
[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
㈣ android應用中的搜索功能怎麼實現的
在APP應用中啟用搜索
在app應用中,至少要執行如下的三個步驟,才能讓app應用能夠進行檢索。如果要提供搜索建議,還需要執行第4步:
編寫搜索配置的XML文件
編寫搜索的activity類
在Android的manifest.xml文件中,對兩面兩個步驟的工作進行配置。
如果要使用搜索建議,則需要增加一個contentprovider。
配置搜索的XML配置文件
首先看下如何配置搜索的XML配置文件。先命名配置文件名稱為searchable.xml,保存在res/xml文件夾中。然後需要設置搜索框的文本,並且應該增加一個hint的提示文本信息,如下代碼所示:
<searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/search_label"> android:hint="@string/search_hint" </searchable>
關於搜索配置文件有很多的配置選項,建議參考Android的手冊可以獲得更多:
http://developer.android.com/guide/topics/search/searchable-config.html。
增加搜索的Activity
當用戶進行搜索時,Android調用activity進行搜索,代碼如下:
publicclass SampleSearchActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleIntent(getIntent()); }public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleIntent(getIntent()); } public void onNewIntent(Intent intent) { setIntent(intent); handleIntent(intent); } public void onListItemClick(ListView l, View v, int position, long id) { // 點每個搜索結果時的處理代碼 } private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); doSearch(query); } } private void doSearch(String queryStr) { //執行真正的查詢結果處理 } }
在上面的代碼中,在handleIntent方法中,當按下搜索按鈕,系統就會自動發送Intent,action是Intent.ACTION_SEARCH,然後通過intent.getStringExtra(SearchManager.QUERY);獲得要搜索的字元串。
其中為什麼要包含onNewIntent()方法呢?主要是因為Android的back後退機制。Android會默認把每一個新的activity放到activity棧的頂部。如果用戶點了後退鍵,則會關閉棧頂部的activity。嘗試考慮一種情況,用戶搜索一個內容並且系統列出了結果,如果用戶發現結果不是他所要的,或者希望重新檢索,則會重新點擊搜索按鍵,這樣將會產生一個新的搜索activity的實例,在activity棧中就會有兩個搜索的activity,這是開發者並不期待的,所以,需要將這個搜索的activity聲明為singleTop類型的activity,這樣的話,無論用戶按返回鍵還是盡心個多次的搜索,在acitivty棧中始終保持的是一個搜索activity的實例。因為當activity被設置為singleTop的載入模式時,如果堆棧的頂部已經存在了該Activity,那麼,它便不會重新創建,而是調用onNewIntent。如果,該Activity存在,但不是在頂部,那麼該Activity依然要重新創建。
mainifest配置文件
接下來,需要對manifest配置文件進行配置,必須要對其中進行如下配置:
搜索的activity.
使用搜索的intent
activity啟動模式
searchable.xml中的元數據
更多的定義搜索的元數據
下面是典型的一個搜索的配置
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".YourApp" > <meta-data android:name="android.app.default_searchable" android:value=".YourSearchActivity" /> <activity android:label="@string/app_name" android:launchMode="singleTop" android:name=".YourSearchActivity" > <intent-filter > <action android:name="android.intent.action.SEARCH" /> </intent-filter> <intent-filter > <action android:name="android.intent.action.VIEW" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> </application>
在上面的典型配置中,要注意如下幾點:
1)由於當調用搜索activity時,Android調用的是android.intent.action.SEARCH作為搜索的intent,所以必須在intent-filter中包含android.intent.action.SEARCH。
2)在<meta-data>中,指出了searchable.xml的位置
3)同樣在<meta-data>中,通過:
<meta-data android:name="android.app.default_searchable" android:value=".YourSearchActivity" />
指出了當執行搜索的字元串提交時,將調用哪一個activity去進行處理。
㈤ android上如何實現一個搜索效果,搜索框動態展開
使用SearchView。
SearchView顧名思義就是一個搜索視圖,和之前講解的自動匹配的輸入框類似。只不過他有自己特有的監聽器,並且可以實時得到用戶輸入的結果。
還不明白者可去Google一下SearchView,基本上就明白了。在你的menu目錄下編寫一個xxx.xml,如果要收縮的效果的話,需要配置這個屬性:android:showAsAction="collapseActionView"
㈥ Android中如何讓一個EditView被點擊後出現搜索框,搜索框已經實現
Android有自帶的一個控制項AutoCompleteTextView
具體用法如下:
java">main.xml代碼如下:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="請選擇你喜歡的歌曲"
android:completionThreshold="1"
android:dropDownHorizontalOffset="20dp"
android:ems="10"
android:text="AutoCompleteTextView">
<requestFocus/>
</AutoCompleteTextView>
</LinearLayout>
java代碼為:
importandroid.app.Activity;
importandroid.graphics.Bitmap;
importandroid.graphics.BitmapFactory;
importandroid.graphics.drawable.BitmapDrawable;
importandroid.os.Bundle;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.View.OnTouchListener;
importandroid.widget.ArrayAdapter;
importandroid.widget.AutoCompleteTextView;
importandroid.widget.Button;
importandroid.widget.ImageView;
{
//定義字元串數組作為提示的文本
String[]books=newString[]{"rollen","rollenholt","rollenren","roll"};
@Override
protectedvoidonCreate(BundlesavedInstanceState){
//TODOAuto-generatedmethodstub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//創建一個ArrayAdapter封裝數組
ArrayAdapter<String>av=newArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,books);
AutoCompleteTextViewauto=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
auto.setAdapter(av);
}
}
㈦ android 一般 搜索框 是用searchview 嗎
1、SearchView是搜索框組件,它可以讓用戶在文本框里輸入文字,通過監聽器取得用戶的輸入,當用戶點擊搜索時,監聽器執行實際的搜索。 2、SearchView組件的常用方法如下: ①setIconifiedByDefault(boolean iconified) ===> 設置搜索框默認是否自動縮小為圖標。 ②setOnQueryTextListener(SearchView,OnQueryTextListener listener) ===> 為搜索框設置監聽器 ③setSubmitButtonEnabled(boolean enabled) ===> 設置是否顯示搜索按鈕 ④setQueryHint(CharSequence hint) ===> 設置搜索框內的默認顯示的提示文本 3、為SearchView增加一個配套的ListView,則可以為其增加自動完成的功能,即ListView用於為SearchView顯示自動補齊列表 4、具體實現代碼如下: package org.crazyit.ui; import android.os.Bundle; import android.text.TextUtils; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SearchView; import android.widget.Toast; import android.app.Activity; public class SearchViewTest extends Activity implements SearchView.OnQueryTextListener { private SearchView sv; private ListView lv; // 自動完成的列表 private final String[] mStrings = { "aaaaa", "bbbbbb", "cccccc", "ddddddd" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lv = (ListView) findViewById(R.id.lv); lv.setAdapter(new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1, mStrings)); lv.setTextFilterEnabled(true);//設置lv可以被過慮 sv = (SearchView) findViewById(R.id.sv); // 設置該SearchView默認是否自動縮小為圖標 sv.setIconifiedByDefault(false); // 為該SearchView組件設置事件監聽器 sv.setOnQueryTextListener(this); // 設置該SearchView顯示搜索按鈕 sv.setSubmitButtonEnabled(true); // 設置該SearchView內默認顯示的提示文本 sv.setQueryHint("查找"); } // 用戶輸入字元時激發該方法 @Override public boolean onQueryTextChange(String newText) { Toast.makeText(SearchViewTest.this, "textChange--->" + newText, 1).show(); if (TextUtils.isEmpty(newText)) { // 清除ListView的過濾 lv.clearTextFilter(); } else { // 使用用戶輸入的內容對ListView的列表項進行過濾 lv.setFilterText(newText); } return true; } // 單擊搜索按鈕時激發該方法 @Override public boolean onQueryTextSubmit(String query) { // 實際應用中應該在該方法內執行實際查詢 // 此處僅使用Toast顯示用戶輸入的查詢內容 Toast.makeText(this, "您的選擇是:" + query, Toast.LENGTH_SHORT).show(); return false; } } </string>
㈧ Android 系統搜索框 如何限制輸入字數長度
android 搜索框就是一個EditText輸入控制項,或者是EditText的子類
長度限制方式有以下幾種:
方法一:
在 xml 文件中設置文本編輯框屬性作字元數限制
如:android:maxLength="10" 即限制最大輸入字元個數為10
方法二:
在代碼中使用InputFilter 進行過濾
//editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)}); 即限定最大輸入字元數為20
示例代碼如下:
{
/**.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditTexteditText=(EditText)findViewById(R.id.entry);
editText.setFilters(newInputFilter[]{newInputFilter.LengthFilter(20)});
}
}
方法三:
利用 TextWatcher 進行限制,TextWatcher是注冊一個內存輸入的改變事件,當你的輸入框輸入字元和刪除字元都會觸發
實現代碼如下:
packagecie.textEdit;
importandroid.text.Editable;
importandroid.text.Selection;
importandroid.text.TextWatcher;
importandroid.widget.EditText;
/*
*監聽輸入內容是否超出最大長度,並設置游標位置
**/
{
privateintmaxLen=0;
privateEditTexteditText=null;
publicMaxLengthWatcher(intmaxLen,EditTexteditText){
this.maxLen=maxLen;
this.editText=editText;
}
publicvoidafterTextChanged(Editablearg0){
//TODOAuto-generatedmethodstub
}
publicvoidbeforeTextChanged(CharSequencearg0,intarg1,intarg2,
intarg3){
//TODOAuto-generatedmethodstub
}
publicvoidonTextChanged(CharSequencearg0,intarg1,intarg2,intarg3){
//TODOAuto-generatedmethodstub
Editableeditable=editText.getText();
intlen=editable.length();
if(len>maxLen)
{
intselEndIndex=Selection.getSelectionEnd(editable);
Stringstr=editable.toString();
//截取新字元串
StringnewStr=str.substring(0,maxLen);
editText.setText(newStr);
editable=editText.getText();
//新字元串的長度
intnewLen=editable.length();
//舊游標位置超過字元串長度
if(selEndIndex>newLen)
{
selEndIndex=editable.length();
}
//設置新游標所在的位置
Selection.setSelection(editable,selEndIndex);
}
}
}
有關EditText 即Android輸入框的更多用法,建議查看官網API文檔
㈨ android studio搜索框設置
android studio全局搜索的方法:
1、使用快捷鍵Ctrl + Shift + F來搜索
2、打開搜索框進行搜索
操作路徑:Edit -> Find -> Findto open find search box.
㈩ 如何使用Android的搜索框架
當你需要在你的應用程序中提供搜索服務時,通過使用Android的搜索框架,應用程序將顯示一個自定義搜索對話框來處理用戶的搜索請求。通過一個簡單的搜索按鈕或從您的應用程序中調用API,搜索對話框就會顯示在屏幕的頂部,並會自動顯示應用程序圖標。
本文將教你如何為你的應用程序提供一個自定義搜索對話框。這樣做,給您的用戶提供一個標准化的搜索體驗,並能增加如語音搜索和搜索建議等功能。
基礎知識
Android的搜索框架將代您管理的搜索對話框,您不需要自己去開發一個搜索框,不需要擔心要把搜索框放什麼位置,也不需要擔心搜索框影響您當前的界面。所有的這些工作都由SearchManager類來為您處理(以下簡稱「搜索管理器」),它管理的Android搜索對話框的整個生命周期,並執行您的應用程序將發送的搜索請求,返回相應的搜索關鍵字。
當用戶執行一個搜索,搜索管理器將使用一個專門的Intent把搜索查詢的關鍵字傳給您在配置文件中配置的處理搜索結果的Activity。從本質上講,所有你需要的就是一個Activity來接收Intent,然後執行搜索,並給出結果。具體來說,你需要的做的事就包括以下內容:
一個搜索配置
我們用個XML配置文件來對搜索對話框進行配置,包括一些功能的配置,如文本框,設置語音搜索和搜索建議中顯示的提示文字等。
一個用來處理搜索請求的Activity
這個Activity用來接收搜索查詢的內容,然後搜索您的數據並顯示搜索結果。
一種用戶執行搜索的途徑
默認情況下,一旦你配置了一個可搜索的Activity,設備搜索鍵(如果有)將調用搜索對話框。然而,你應該始終提供另一種手段,讓用戶可以調用搜索對話框,如在選項菜單中的搜索按鈕或其他用戶界面上的按鈕,因為不是所有的設備提供一個專門的搜索鍵。
創建一個搜索對話框配置文件
搜索框配置文件是一個用來配置您的應用程序中搜索框的設置的XML文件,這個文件一般命名為searchable.xml,並且必須保存在項目的res/xml/目錄下。
配置文件的根節點必須為,可以有一個或多個屬性。如下所示:
[html] view
plainprint?
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/searchLabel" android:hint="@string/searchHint">
</searchable>
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/searchLabel" android:hint="@string/searchHint">
</searchable>
上面的配置文件中,除android:hint屬性外,其它都是一個搜索對話框必須的配置項,android:label是一個必須的屬性,它的值為一個string資源引用,不能直接用字元串,通常會是應用程序的名稱(盡管它是一個必須的屬性,但通常情況下是不顯示出來的,除非你開啟了搜索建議功能)。android:hint是配置搜索框的輸入提示信息,也必須引用string.xml中配置的字元串資源,不能直接使用字元串。
可以配置很多的屬性,但大部分屬性都只是在使用搜索建議和語音搜索時進行配置,盡管如此,我們建議你一定要配置android:hint,用於提示用戶需要輸入的信息。
接下來,你需要把這個配置文件放到你的應用程序中。
創建一個可用於搜索的Activity
當用戶從一個搜索框執行搜索時,搜索管理器(Search
Manager)會通過ACTION_SEARCH Intent
把要搜索的內容(關鍵字)發送到一個可執行搜索的Activity。這個Acitivity查詢數據並顯示結果。
定義一個可搜索的Activity
如果你還沒有準備好,那麼就創建一個用來執行搜索的Activity,聲明它可以響應ACTION_SEARCH
Intent ,並且增加搜索框配置信息。為此,你需要添加一個元素和一個元素在你的manifest文件中的節點。如下所示:
[html] view
plainprint?
<application ... >
<activity android:name=".MySearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
...
</application>
<application ... >
<activity android:name=".MySearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
...
</application>
中的android:name屬性值必須為」android.app.searchable」,android:resource屬性值必須引用上面提到的res/xml/目錄下的搜索配置文件(本例中的res/xml/searchable.xml)。
請注意,只有配置了上面的meta-data節點的Activity的節點才能執行搜索,如果想在整個應用程序中都可以調用搜索框,可以進行如下配置:
[html] view
plainprint?
<application ... >
<activity android:name=".MySearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity android:name=".AnotherActivity" ... >
</activity>
<!—這個配置就可以讓你在整個應用程序中調用搜索框 -->
<meta-data android:name="android.app.default_searchable"
android:value=".MySearchableActivity" />
...
</application>
<application ... >
<activity android:name=".MySearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity android:name=".AnotherActivity" ... >
</activity>
<!—這個配置就可以讓你在整個應用程序中調用搜索框 -->
<meta-data android:name="android.app.default_searchable"
android:value=".MySearchableActivity" />
...
</application>
上面代碼中android:name=」android.app.default_searchable」
定義一個響應搜索框搜索請求的名稱,android:value指定是由哪個Activity響應並執行搜索。當我們在應用程序中的
OtherAcitivity中執行搜索請求時,MySearchableActivity將會被載入用於執行搜索並顯示搜索結果。
執行一個搜索
當一個Activity聲明為可搜索時,執行實際的搜索包括三個步驟:接收查詢,檢索你的數據,並提交結果。
通常情況下,你的搜索結果需要在一個ListView中展現,所以你用於執行搜索的Acitivity要繼承ListActivity,這樣,可以方便的訪問ListView的Api。
接收搜索查詢
當從搜索對話框執行搜索時,剛才配置的可用於搜索的Acitivity將會被Intent激活,同時帶著一些搜索相關的參數,你需要檢查Intent並做出搜索響應,如下所示:
[java] view
plainprint?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);Intent intent = getIntent();
//判斷是否是搜索請求
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
//獲取搜索的查詢內容(關鍵字)
String query = intent.getStringExtra(SearchManager.QUERY);
//執行相應的查詢動作
doMySearch(query);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
Intent intent = getIntent();
//判斷是否是搜索請求
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
//獲取搜索的查詢內容(關鍵字)
String query = intent.getStringExtra(SearchManager.QUERY);
//執行相應的查詢動作
doMySearch(query);
}
}
doMySearch()方法將根據關鍵字查詢資料庫,或從網路上查詢數據,如果是耗時的搜索,你還需要使用進度條,來告訴用戶搜索正在進行,最後返回結果後,可以調用ListView的setAdapter()方法將結果顯示在ListView中。
調用搜索對話框
你可以從應用程序中的任何一個地方調用onSearchRequested()方法激活搜索框,比如從菜單中或者一個按鈕等。你也要以在
onCreate()方法中調用setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL),這樣,當用戶按下鍵盤上的按鍵時,將會自動激活搜索框。
搜索框和普通對話框一樣,浮動在屏幕的最上方,它不會改變任何Activity堆棧狀態,沒有任何Activity生命周期中的方法會被調用,只是當搜索框出現就,正在運行的Activity會失去輸入焦點。
如果你要在執行搜索時,進行別的操作,可以重寫onSearchRequested()方法,如下所示:
[java] view
plainprint?
@Override
public boolean onSearchRequested() {
//這個方法中干你想乾的事,比如做一些被始化工作
pauseSomeStuff();
return super.onSearchRequested();
}
@Override
public boolean onSearchRequested() {
//這個方法中干你想乾的事,比如做一些被始化工作
pauseSomeStuff();
return super.onSearchRequested();
}
如果當前的Activity就是響應搜索請求的Activity時,會有以下兩種情況:
默認情況下,ACTION_SEARCH
Intent將會創建一個新的Activity,並調用onCreate()方法,這個新的Activity會顯示在最前面,你將同時有兩個
Activity實例。當你按「返回」鍵里,會回到沒有執行搜索前的一個Activity。
另一種情況是配置了android:launchMode=」singleTop」的Activity,這時,我們需要在
onNewIntent(Intent)方法中處理搜索請求,如下所示:
[java] view
plainprint?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
handleIntent(getIntent());
}@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
handleIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}
相應的Activity配置如下
[html] view
plainprint?
<activity android:name=".MySearchableActivity"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<activity android:name=".MySearchableActivity"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
如何給搜索框增加參數
要給搜索框傳遞參數,我們需要重寫onSearchRequested()方法,如下所示:
[java] view
plainprint?
@Override
public boolean onSearchRequested() {
Bundle appData = new Bundle();
appData.putBoolean(MySearchableActivity.JARGON, true);
startSearch(null, false, appData, false);
return true;
}
@Override
public boolean onSearchRequested() {
Bundle appData = new Bundle();
appData.putBoolean(MySearchableActivity.JARGON, true);
startSearch(null, false, appData, false);
return true;
}
我們的Activity在收到搜索框的搜索請求時,通過如下方法獲取參數:
[java] view
plainprint?
Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA);
if (appData != null) {
boolean jargon = appData.getBoolean(MySearchableActivity.JARGON);
}
Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA);
if (appData != null) {
boolean jargon = appData.getBoolean(MySearchableActivity.JARGON);
}
最後我們來看看如何使用android的語音搜索:
只需要對我們的搜索配置文件做如下改動,你的搜索就支持語音搜索了,配置文件如下所示:
[html] view
plainprint?
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/searchLabel"
android:hint="@string/searchHint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer">
</searchable>