我一直致力於實施Custom search
在Android
應用程序欄。所以,我在menu_main.xml
在Android中進行自定義搜索?
<item android:id="@+id/action_search"
android:title="search"
android:icon="@drawable/ic_search"
app:showAsAction="ifRoom|collapseActionView"
android:hint="Enter Tags"
app:actionViewClass="android.support.v7.widget.SearchView" />
現在,當我在看HomeActivity
添加下面的代碼。它看起來像這樣:
這是完全正常的!我還沒有實現SearchView
以上的後端代碼。現在,我想在上面Search bar
用戶添加一些以下特點可以用標籤搜索(使用標籤搜索意味着,如果有兩個詞之間的空間,然後我就會把它們當做標籤)。這與
Pintreset
應用非常相似。此外我想從
Search Bar
得到這些標籤,並把Get
請求參數。截圖
問題
- 現在,忘了
Style
。我只想知道如何在我的Search Bar
中實現此目標? - 我該如何在每個標籤上加上這個十字標記的框
Android app bar
?
任何幫助將是可觀的。
編輯-1
我加入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.menu_main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
.getActionView();
if (null != searchView) {
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
}
SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
public boolean onQueryTextChange(String newText) {
// this is your adapter that will be filtered
return true;
}
public boolean onQueryTextSubmit(String query) {
//Here u can get the value "query" which is entered in the search box.
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
return super.onCreateOptionsMenu(menu);
}
我收到提交文本onCreateOptionsMenu.onQueryTextSubmit
方法。我現在應該怎麼做?
感謝您的回答。將'mSearchAutoComplete =(AutoCompleteTextView)findViewById(android.support.v7.appcompat.R.id.search_src_text);'將是'mSearchAutoComplete =(AutoCompleteTextView)findViewById(android.support.v7.appcompat.R.id.search_src_text); '? –
我沒有顯示任何'AutoCompleteTextView'。用戶將添加一些帶空格的字符串。之後,我需要採取這些措辭並進行查詢 –
@AmitPal是的,你不顯示,但這是它如何在Android源代碼內部實現。看看這裏 - http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/widget/SearchView.java#116。 – Oleksandr