2014-06-10 85 views
1

我想禁用鍵入區域中的某些按鈕。 例如,我想要禁用鍵盤中的1,2,3個按鈕。 我想學習是否有可能?可以禁用android輸入中的一些輸入按鈕

enter image description here

+0

您可以覆蓋與該按鈕的情況下,對於示例[覆蓋後退按鈕](http://stackoverflow.com/questions/3141996/android-how-to-override-the-back-button-so-it-doesnt-finish-my-activity) – user2450263

+0

我該怎麼辦Rride鍵盤輸入類型? – ibrahimyilmaz

+0

1. [處理鍵盤操作](https://developer.android.com/training/keyboard-input/commands.html)和2. [覆蓋Android本機鍵盤](http://stackoverflow.com/questions/17758751/overriding-android-native-keyboard) – user2450263

回答

0

你可以在你的XML使用下面的代碼

<EditText 
    android:inputType="text" 
    android:digits="0,4,5,6,7,8,9 
/> 
+0

我會測試它,謝謝 – ibrahimyilmaz

+0

我仍然可以點擊其他按鈕我想看到它們禁用。 – ibrahimyilmaz

0

您可以使用下面的代碼或者在Java方面

private List<Char> allowedChars = new ArrayList(Char); 
allowedChars.add(...); 
allowedChars.add(...); 
allowedChars.add(...); 
allowedChars.add(...); 
InputFilter filter = new InputFilter() { 
     public CharSequence filter(CharSequence source, int start, int end, 
Spanned dest, int dstart, int dend) { 
       for (int i = start; i < end; i++) { 
         // Your condition here 
         if (!allowedChars.contains(source.charAt(i)))) { 
           return ""; 
         } 
       } 
       return null; 
     } 
}; 

edit.setFilters(new InputFilter[]{filter});