Android에서 EditText를 비활성화하는 방법
EditText
Android 에서 필드 입력을 비활성화하려면 어떻게 해야합니까?
나는 안드로이드의 버그라고 생각한다.이 패치를 추가하여 수정할 수있다. :)
이 링크 질문 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의 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
- First create the object
- Declare EditText et1;
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
'Programing' 카테고리의 다른 글
C ++ 파일 스트림 (fstream)을 사용하여 파일 크기를 어떻게 결정할 수 있습니까? (0) | 2020.10.26 |
---|---|
C는 오픈 소스입니까? (0) | 2020.10.26 |
프로세스가 시작될 때까지 Process.Start 대기 만들기 (0) | 2020.10.26 |
Serializable 특성 사용과 ISerializable 구현의 차이점은 무엇입니까? (0) | 2020.10.25 |
Dockerfiles 또는 이미지 커밋을 사용해야합니까? (0) | 2020.10.25 |