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

Try this may work for you

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 });
    }

}

If you want to add spaces you can give space after the last digit.

  android:digits="0123456789qwertzuiopasdfghjklyxcvbnm "