Android: Disable soft keyboard at all EditTexts

前端 未结 13 2183
失恋的感觉
失恋的感觉 2020-11-27 06:23

I am working on a dialog at Android with a few EditTexts. I\'ve put this line at the onCreate() in order to disable the soft keyboard:



        
相关标签:
13条回答
  • 2020-11-27 06:56
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edSearch.getWindowToken(), 0);
    
    0 讨论(0)
  • 2020-11-27 06:57

    Try this out..

    edittext.setInputType(InputType.TYPE_NULL);      
    if (android.os.Build.VERSION.SDK_INT >= 11)   
    {  
        edittext.setRawInputType(InputType.TYPE_CLASS_TEXT);  
        edittext.setTextIsSelectable(true);  
    }
    
    0 讨论(0)
  • 2020-11-27 06:58

    by set EditText focusable->false, keyboard will not opened when clicked

    <EditText
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:focusable="false" />
    
    0 讨论(0)
  • 2020-11-27 06:59

    create your own class that extends EditText and override the onCheckIsTextEditor():

    public class NoImeEditText extends EditText {
        public NoImeEditText(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        @Override
        public boolean onCheckIsTextEditor() {
            return false;
        }
    }
    
    0 讨论(0)
  • 2020-11-27 07:01

    You can do that:

    textView.setOnClickListener(null);
    

    It will disable the keyboard to the textView and the click will not work anymore.

    0 讨论(0)
  • 2020-11-27 07:02

    If you take look on onCheckIsTextEditor() method implementation (in TextView), it looks like this:

    @Override
    public boolean onCheckIsTextEditor() {
        return mInputType != EditorInfo.TYPE_NULL;
    }
    

    This means you don't have to subclass, you can just:

    ((EditText) findViewById(R.id.editText1)).setInputType(InputType.TYPE_NULL); 
    

    I tried setting android:inputType="none" in layout xml but it didn't work for me, so I did it programmatically.

    0 讨论(0)
提交回复
热议问题