![](/img/trans.png)
[英]What's the difference between android.app.default_searchable and android.app.searchable meta-data?
[英]How to apply the search intent filter and android.app.searchable to all activities?
我的Android應用程序中有很多活動,需要使用SearchView實現ActionBar。
我最初只是將以下幾行添加到我的SearchActivity中:
<activity android:name=".activity.SearchActivity" 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>
但是, searchManager.getSearchableInfo(getComponentName());
從AnotherActivity1
調用時, onCreateOptionsMenu
返回null
。
因此,我還向AnotherActivity1
添加了intent-filter
和android.app.searchable
元數據,該數據適用於AnotherActivity1
SearchView。
但是我有很多這樣的活動-我應該只為所有這些片段復制粘貼此XML代碼段,還是缺少一些更優雅的解決方案?
嗯,我想我自己想通了。
采用
searchManager.getSearchableInfo(new ComponentName(this, SearchActivity.class));
代替
searchManager.getSearchableInfo(getComponentName());
然后,我必須僅將intent-filter
和meta-data
應用於SearchActivity
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.