【问题标题】:it is possible to disable some of input buttons in android input [duplicate]可以禁用android输入中的一些输入按钮[重复]
【发布时间】:2014-06-10 12:15:56
【问题描述】:

我想禁用输入区域中的一些按钮。 例如我想禁用键盘上的 1,2,3 按钮。 我想知道有没有可能?

【问题讨论】:

标签: android android-layout android-keypad


【解决方案1】:

您可以在 xml 中使用以下代码

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

【讨论】:

  • 我会测试一下谢谢
  • 我仍然可以点击我希望看到它们被禁用的其他按钮。
【解决方案2】:

您可以在 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});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多