How to show Android keyboard with symbols mode by default?

前端 未结 5 909
余生分开走
余生分开走 2020-12-06 01:55

I have a EditText component, and, of course, if you click on it, the Android keypad is shown, allowing the user to input text. As far as I know, all Android sof

5条回答
  •  臣服心动
    2020-12-06 02:17

    Programmatically it is possible with little bit of tweak to the usual flow. First you have to set editText as:

    editText.setInputType(InputType.TYPE_CLASS_NUMBER);

    Then you have to listen for keyevent. On pressing of pound set the InputType again to InputType.TYPE_CLASS_TEXT. This should work as it works for me.

    editText.setOnKeyListener(new View.OnKeyListener() 
            {
             @Override
             public boolean onKey(View v, int keyCode, KeyEvent event) {
                                    // TODO Auto-generated method stub
                                    Log.d("KeyBoard", "Keyboard Test Key Hit");
    
             switch (keyCode) {
             KeyEvent.KEYCODE_POUND:
                                                                                          if(editText.setInputType(InputType.TYPE_CLASS_TEXT);
             {
    
             editText.setInputType(InputType.TYPE_CLASS_TEXT);
             return true;
    
         }
    

    Same thing I've answered i: EditText with number keypad by default, but allowing alphabetic characters

提交回复
热议问题