EditText not editable

2019-01-22 05:34发布

I'm trying to put a EditText as not editable with this code:

<EditText android:id="@+id/outputResult"
          android:inputType="text"
          android:editable="false"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="@string/result" />

I had to add this for not editable

android:focusable="false" 

Am I doing something wrong?

Thanks you verry much

8条回答
地球回转人心会变
2楼-- · 2019-01-22 06:15

I guess I am late but use following together to make it work:

 android:inputType="none"
 android:enabled="false"
查看更多
ら.Afraid
3楼-- · 2019-01-22 06:21

I had this problem, too.

I did this:

<EditText
    android:layout_width="30dp"
    android:layout_height="wrap_content"
    android:id="@+id/yourid"
    android:editable="false"
    android:inputType="none" />
查看更多
迷人小祖宗
4楼-- · 2019-01-22 06:22

If you really want to use an editText and not a textView, then consider using these three:

android:focusable="false"

android:clickable="false"

android:longClickable="false"

EDIT: The "longClickable" attribute disables the long press actions that cause the "Paste" and or "Select All" options to show up as a tooltip.

查看更多
甜甜的少女心
5楼-- · 2019-01-22 06:23
 <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/editTexteventdate"
            android:background="@null"
            android:hint="Date of Event"
            android:textSize="18dp"
            android:textColor="#fff"
            android:editable="false"
            android:focusable="false"
            android:clickable="false"

            />

Add this

android:editable="false"

android:focusable="false"

android:clickable="false"

its work for me

查看更多
一夜七次
6楼-- · 2019-01-22 06:26

Add below line in youe xml edittext.

android:editable="false"
android:focusable="false"
android:clickable="false"

Its working for me

查看更多
beautiful°
7楼-- · 2019-01-22 06:33

In case you want to make an EditText not editable from code:

void disableInput(EditText editText){
    editText.setInputType(InputType.TYPE_NULL);
    editText.setTextIsSelectable(false);
    editText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v,int keyCode,KeyEvent event) {
                return true;  // Blocks input from hardware keyboards.
        }
    });
}

In case you want to remove the horizontal line of your EditText, just add:

editText.setBackground(null);

If you want to let users copy the content of the EditText then use:

editText.setTextIsSelectable(true);
查看更多
登录 后发表回答