はじめに
今回この記事を書こうと思ったきっかけは、 EditTextがある条件の時に使えなくなるケースがあり 他Viewと同じようにenabledを操作して簡単に不具合を治せると思っていたところ 上手くいかず。その際に調べたところいくつか出てきたのでそれを記事にしていこうと思います。
この記事では、5つそれぞれの使い方と一言メモ的なものを残しておこうと思います。
enabled
活性・非活性を切り替える
単純に使用させない時などに使う
EditText.enabled = true
<EditText ...
android:enable="true">
clickable
click可能不能を切り替える
clickイベントを使用するときに切り替える
EditText.clickable = true
<EditText ...
android:clickable="true">
cursorVisible
カーソルの表示・非表示を切り替える
視覚的にEditTextが使用できる状態であることを表せる
EditText.cursorVisible = true
<EditText ...
android:cursorVisible="true">
focusable
EditTextのフォーカス可能・不可能を切り替える
上書きやコピペなどをさせたくない時に使う
EditText.focusable = true
<EditText ...
android:focusable="true">
focusableInTouchMode
Viewをタッチすることでフォーカス可能・不可能を切り替える
今回の不具合はこれを追加したら治った
FOCUSABLE_AUTOをしているするとclick可能な時だけフォーカス可能にできる
EditText.focusableInTouchMode = true
<EditText ...
android:focusableInTouchMode="true">
参考