2014-08-31 82 views
-1

在Android的搜索活動中,當用戶觸摸十字按鈕以清除搜索框時,是否可以處理該事件? 我談論的按鈕在屏幕截圖交叉:可搜索的活動,處理事件

Searchable activity bar

這是清單的定義:

<activity 
     android:name=".MySearchActivity" 
     android:theme="@android:style/Theme.Dialog"> 
     <intent-filter> 
      <action android:name="android.intent.action.SEARCH" /> 
     </intent-filter> 
     <meta-data android:name="android.app.searchable" 
        android:resource="@xml/searchable"/> 
    </activity> 

這是在元數據中引用的XML:

<searchable xmlns:android="http://schemas.android.com/apk/res/android" 
    android:label="@string/app_name" 
    android:hint="@string/search_hint" /> 
+1

你試過OnQueryTextListener嗎? – pskink 2014-08-31 18:15:37

+0

感謝@pskink它工作正常,回答這個問題,(你可以添加它作爲評論,所以我可以接受的迴應) – otonakav 2014-08-31 18:59:28

回答

1

使用SearchView.OnQueryTextListener界面,特別是見onQueryTextChange(字符串newText)方法