EditText
Androidでフィールドへの入力を無効にするにはどうすればよいですか?
18 に答える
EditText.setFocusable(false)
編集を無効にして編集EditText.setFocusableInTouchMode(true)
を有効にするために使用できます。
コード内:
editText.setEnabled(false);
または、XML では次のようになります。
android:editable="false"
Androidのバグだと思います..このパッチを追加することで修正できます:)
これらのリンクの
質問1
と
質問2を確認してください
それが役に立つことを願っています。
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.setFocusable(false);
edittext.setEnabled(false);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
//removes on screen keyboard
edittext.setInputType(0)
編集テキストを表示したいが値を入力したくない場合は、書くことができます
以下のコードは、Android の EditText を無効にします。
editText.setEnabled(false);
Android で編集テキストを無効にするには:
editText.setEnabled(false);
親にこれを書いてください:
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
例:
<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" />