title: Set an Edittext to read only and back to editable
body: <p>I've found many questions about setting an edit text to readOnly or to editable, but all of them only work for some specific scenarios.
  I need the following functionality:</p>
  
  <p>An Edittext widget which is editable should be set to readonly programmatically. When it is readonly, it shouldn't be possible to input data, but the current content should be selectable to copy. The same field should set back to editable to the same state as before, so allow input and select the text for copy/paste.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>        if (readOnly)
          {
              _text.setTextColor(Color.GRAY);
              _keyListener = _text.getKeyListener();
              _text.setKeyListener(null);
          }
          else
          {
              _text.setTextColor(_foreground);
              if (_keyListener != null)
              {
                  _text.setKeyListener(_keyListener);
              }
              _text.setFocusable(true);
          }
  </code></pre>
  
  <p>I already tried the following methods:</p>
  
  <ul>
  <li>Call <code>setTextIsSelectable()</code> in the readonly part. This enables selection of text in the readonly field. But if I change it back to editable, the field is still only selectable.</li>
  <li>Set the inputtype to null for readonly state and set it back to the previous state to set it editable. With this, the the field isn't editable after setting it back to editable.</li>
  </ul>
  
  <p>I think I forgot to set some kind of Listener or property. Maybe one of you knows which one that is.</p>
  
  <p>Edit:
  Tried the following:
  <a href="https://stackoverflow.com/questions/4297763/disabling-of-edittext-in-android">Disabling of EditText in android</a>
  But it only works as long as I won't use the <code>setTextIsSelectable()</code> to make the readonly text selectable. If I set this value and switch back to editable, the field is only selectable, but not editable.</p>
  
  <p>Thanks</p>