我正在开发键盘应用程序,但遇到了问题.我想以编程方式在 android 的 EditText 中限制/阻止软键盘中的某些特殊字符.
I am developing an application for keyboard, but i am geting an issue. I want to restrict/block some special character from soft keyboard in EditText in android programmatically.
那么,有什么办法可以限制在 android 的编辑文本中输入任何特殊字符.
So, Is there any way i can restrict any special character input in edit text in android.
如果有人有想法,请回复.
If anyone have idea,Please reply.
提前致谢.
试试这个可能对你有用
public class MainActivity extends Activity {
private EditText editText;
private String blockCharacterSet = "~#^|$%&*!";
private InputFilter filter = new InputFilter() {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (source != null && blockCharacterSet.contains(("" + source))) {
return "";
}
return null;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
editText.setFilters(new InputFilter[] { filter });
}
}
这篇关于如何通过android中的软键盘以编程方式将我的EditText输入限制为一些特殊字符,如反斜杠(/),tild(〜)等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!