Programing

Android에서 EditText를 비활성화하는 방법

crosscheck 2020. 10. 26. 07:41
반응형

Android에서 EditText를 비활성화하는 방법


EditTextAndroid 에서 필드 입력을 비활성화하려면 어떻게 해야합니까?


나는 안드로이드의 버그라고 생각한다.이 패치를 추가하여 수정할 수있다. :)
이 링크 질문 1질문 2를 확인한다.

도움이 되길 바랍니다.


를 사용 EditText.setFocusable(false)하여 편집을 비활성화 할 수 있습니다
EditText.setFocusableInTouchMode(true).


코드에서 :

editText.setEnabled(false);

또는 XML에서 :

android:editable="false"

editText당신이 EditText반대 한다고 가정 합니다.

editText.setEnabled(false);

다음 방법을 시도해 볼 수 있습니다.

 private void disableEditText(EditText editText) {
    editText.setFocusable(false);
    editText.setEnabled(false);
    editText.setCursorVisible(false);
    editText.setKeyListener(null);
    editText.setBackgroundColor(Color.TRANSPARENT); 
 }

EditText 활성화 :

EditText 활성화

비활성화 된 EditText :

비활성화 된 EditText

그것은 저에게 효과적이며 도움이되기를 바랍니다.


edittext의 focusable 속성을 "false"로 설정하면 완료됩니다.

<EditText
        android:id="@+id/EditTextInput"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:gravity="right"
        android:cursorVisible="true">
    </EditText>

아래 옵션이 작동하지 않습니다.

코드에서 :

editText.setEnabled(false); 또는 XML에서 : android:editable="false"


Edittext edittext = (EditText)findViewById(R.id.edit);
edittext.setEnabled(false);

아래 코드는 Android에서 EditText를 비활성화합니다.

editText.setEnabled(false);

edittext.setFocusable(false); 
edittext.setEnabled(false);

InputMethodManager imm = (InputMethodManager)
  getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
  //removes on screen keyboard

활성화 :

private void enableEditText() {
    mEditText.setFocusableInTouchMode(true);
    mEditText.setFocusable(true);
    mEditText.setEnabled(true);
}

비활성화 :

private void disableEditText() {
    mEditText.setEnabled(false);
    mEditText.setFocusable(false);
    mEditText.setFocusableInTouchMode(false);
}

Android에서 편집 텍스트를 비활성화하려면 :

editText.setEnabled(false);

You can write edittext.setInputType(0) if you want to show the edittext but not input any values


Write this in parent:

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

Example:

<RelativeLayout 
android:id="@+id/menu_2_zawezanie_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/menu_2_horizontalScrollView"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:background="@drawable/rame">

<EditText
    android:id="@+id/menu2_et"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/menu2_ibtn"
    android:gravity="center"
    android:hint="@string/filtruj" >
</EditText>
<ImageButton
    android:id="@+id/menu2_ibtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:background="@null"
    android:src="@drawable/selector_btn" />


According to me...if you have already declared the edittext in the XML file and set the property in the XML file "android:enabled=false" and disable at runtime to it at that time in java file adding only 2 or 3 lines

  1. First create the object
  2. Declare EditText et1;
  3. Get by id

    et1 = (EditText) FindViewById(R.id.edittext1);
    et1.setEnabled(false);

You can do enable or disable to every control at run time by java file and design time by XML file.


The XML editable property is deprecated since API LEVEL 15.

You should use now the inputType property with the value none. But there is a bug that makes this functionality useless.

Here you can follow the issue status.

참고 URL : https://stackoverflow.com/questions/5879250/how-to-disable-edittext-in-android

반응형