Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After hours and hours of research, I finally found a solution that works for all API versions. Hope this saves someone's time.</p> <p>If you are developing for API >= 11, the solution is simple, either:</p> <p>1) Add the two properties below in the xml file of EditText</p> <pre><code>android:inputType="none" android:textIsSelectable="true" </code></pre> <p>or</p> <p>2) Programatically do the below</p> <pre><code>myEditText.setInputType(InputType.TYPE_NULL); myEditText.setTextIsSelectable(true); </code></pre> <p>And you're done.</p> <p>If you want to cater for API &lt; 11 as well, I found that there is no way to disable to keyboard from popping out if you wanted to select the text for copy paste purpose. Setting focusable to false will disable the keyboard but it doesn't help because it disables your ability to select text too. Any other solutions I found in stackoverflow all either doesn't work or disables text selection at the same time too.</p> <p>One ugly way to solve this is as such..</p> <p>First, add this property in the xml file of EditText</p> <pre><code>android:editable="false" </code></pre> <p>Yes this is deprecated, but necessary for making the EditText not editable in API version &lt; 11.</p> <p>Next, we will need to hide the keyboard as soon as it shows up, so that we can continue selecting text without the keyboard blocking the way.</p> <p>Use this code below to detect keyboard showing up (solution obtained from <a href="https://stackoverflow.com/a/9108219/1241783">https://stackoverflow.com/a/9108219/1241783</a>), and hide it immediately. </p> <pre><code>if (android.os.Build.VERSION.SDK_INT &lt; android.os.Build.VERSION_CODES.HONEYCOMB) { final View activityRootView = findViewById(R.id.activityRoot); activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); //r will be populated with the coordinates of your view that area still visible. activityRootView.getWindowVisibleDisplayFrame(r); int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top); if (heightDiff &gt; 100) { // if more than 100 pixels, its probably a keyboard... //Hide the keyboard instantly! if (getCurrentFocus() != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } } } }); } </code></pre> <p>It works for my case. Though you can see the keyboard showing up in a split second (which is the ugly part) but I can't think of any other way to get this to work at the time of writing. If you have a better solution, please leave a comment!</p> <p>Let me know too if this saves someone's time :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload