How to make EditText not editable through XML in Android?

后端 未结 27 1954
梦谈多话
梦谈多话 2020-11-28 17:35

Can anyone tell me how to make an EditText not editable via XML? I tried setting android:editable to false, but

  1. it is de
27条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 18:23

    I tried to do:

    textView.setInputType( InputType.TYPE_NULL );
    

    which should work, but for me it did not.

    I finished with this code:

    textView.setKeyListener(new NumberKeyListener() {
        public int getInputType() {
            return InputType.TYPE_NULL;
        }
    
        protected char[] getAcceptedChars() {
            return new char[] {};
        }
    });
    

    which works perfectly.

提交回复
热议问题