How can restrict my EditText input to some special character like backslash(/),tild(~) etc by soft keyboard in android programmatically

前端 未结 10 1871
故里飘歌
故里飘歌 2020-12-08 04:02

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 programmatic

10条回答
  •  失恋的感觉
    2020-12-08 04:32

    First need to add DigitsKeyListener for allowing characters and then setRawInputType to edittext field

    edit_field.setKeyListener(DigitsKeyListener.getInstance("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
    
    
    edit_field.setRawInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
    

提交回复
热议问题