2011-11-28 71 views
4

我無法設置數字輸入類型爲我的ActionBar中的SearchView。我有以下searchable.xml文件在我RES/XML文件夾:在ActionBar中將數字輸入類型設置爲SearchView

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

而且我設置了搜索配置到搜索查看如下:

// Get the SearchView and set the searchable configuration 
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); 
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 

的search_hint設置正確,但行android:inputType =「number」似乎沒有效果,即沒有出現數字小鍵盤。

有沒有人有解決方案?

+0

通過使用自定義EditText上,而不是搜索查看的問題解決了。 –

回答

2

在searchable.xml佈局文件添加此:

android:numeric="decimal" 

或者如果沒有有用的,然後嘗試,

android:inputType="phone"

讓我知道發生什麼事。

+0

數字不是可搜索的屬性,不幸的是,將inputType設置爲手機並沒有幫助。 –

+0

看看這個[創建可搜索配置](http://developer.android.com/guide/topics/search/search-dialog.html),然後這[可搜索](http://developer.android.com/guide /topics/search/searchable-config.html#searchable-element),然後[inputType](http://developer.android.com/reference/android/R.attr.html#inputType)。 – user370305

+0

正如您從我的代碼中可以看到的那樣,inputType設置爲「number」,但數字鍵盤不會顯示。 –

0

試試這個

android:inputType="phone" 
+0

似乎數字不是可搜索的屬性。 –

+0

dohh,忘了這個,它被應用於edittext。無論如何,使用inputType手機時,應出現數字鍵盤。 – mihail

+0

不幸的是,即使將inputType設置爲手機,它也不起作用。它適用於edittext,但不適用於SearchView。 –

1

這應該工作:

SearchView searchView = new SearchView(getContext()); 
searchView.setInputType(InputType.TYPE_CLASS_NUMBER); 
+0

看起來像是在工作,但只適用於Android API 14+。我對嗎? (無論如何,問題並未指定API版本) – NLemay

+0

這是正確的。 – lokoko

相關問題