是否有任何搜索欄小部件可用,就像android默認搜索欄?我只想像默認的搜索欄,即時通訊將處理搜索功能。我可以通過使用編輯文本小部件來做到這一點,但我想知道是否有任何現成的小部件可用?android中的搜索欄小部件?
0
A
回答
2
0
您可以使編輯文本像使用TextWatcher類的搜索欄一樣工作。
2
在你onCreate方法查看您可以:
onCreate方法:
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
handleIntent(getIntent());
OnCreateOptionsMenu:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.feed, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return true;
}
菜單:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="br.com.srtorcedor.FeedActivity">
<item android:id="@+id/action_search"
android:icon="@drawable/abc_ic_search"
android:title="@string/search_title"
android:showAsAction="always"
android:actionViewClass="android.widget.SearchView"/>
</menu>
Searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_label"
android:hint="@string/search_hint" >
</searchable>
在該片段中,你需要把下面的方法:
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doSearch(query);
}
}
public void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
private void doSearch(String queryStr) {
Log.i("Your search: ",queryStr);
}
做,你會看到搜索小部件在操作欄上。我希望它可以與你們一起工作。
+0
你將如何在doSearch方法中執行搜索 – 2017-01-30 20:22:41
+0
你沒有提供setIntent() – Takichiii 2017-06-05 01:10:33
相關問題
- 1. Android中ActIonBar外部的搜索欄
- 2. 搜索欄小部件不能開始搜索活動
- 3. Android中的搜索欄
- 4. 搜索操作欄上的小部件不觸發我的搜索活動
- 5. Android:ActionBarSherlock搜索小部件
- 6. Twitter搜索框小部件
- 7. 搜索欄與Android
- 8. 搜索欄發行的Android
- 9. 在zk中搜索窗口小部件
- 10. Android Actionbar搜索窗口小部件實現在ListFragment中
- 11. Android - MapActivity中的搜索工具欄
- 12. 在Android 3.0搜索欄中的更改
- 13. 谷歌搜索欄Android
- 14. 如何使操作欄中的搜索小部件更大?這裏
- 15. UITableView部分索引重疊搜索欄
- 16. 如何調整搜索欄的大小?
- 17. 在Android中顯示搜索欄
- 18. Android Firebase - 在搜索欄中出錯
- 19. 如何在android中實現搜索欄?
- 20. Solr分面搜索構建小部件
- 21. Sitefinity從tamplets搜索小部件也
- 22. WP:覆蓋搜索小部件
- 23. 如何在Android搜索欄模式中實現搜索模式?
- 24. 在android中的流視頻文件的自定義搜索欄
- 25. 的UITableView,搜索欄和部分指數
- 26. 黑莓頂部的搜索欄
- 27. 刪除部分索引標題時,在搜索顯示控制器中調整搜索欄的大小
- 28. 搜索欄來搜索TextViews
- 29. 設置Android的最小值搜尋欄
- 30. 在搜索欄中實現Google搜索
有沒有例子? – vnshetty 2011-05-25 08:13:42