user1662405
user1662405

Reputation: 21

EditText missing cursor

I disabled the soft keyboard via: setInputType(InputType.TYPE_NORMAL) for an EditText view. As I expected, the keyboard gets disabled. The cursor on the view also disappears with it.

I wonder whether there is a way to get the the cursor to return while the keyboard is disabled?

Thanks in advance.

Upvotes: 2

Views: 6920

Answers (3)

User Learning
User Learning

Reputation: 3513

I faced the same problem so i have added the below in manifest file and problem solved . add windowSoftInputMode in your activity:

<activity
    android:name=".YourActivity"
    android:windowSoftInputMode="adjustPan">
</activity>

Upvotes: 0

Carl
Carl

Reputation: 15615

This is a reported issue with Android:

http://code.google.com/p/android/issues/detail?id=27609

I have experienced this myself when disabling the soft keyboard in order to allow an external keyboard to be used. I have not been able to get the cursor back in that case, even using setCursorVisible(true) as described in another answer to this present question.

There are a few workarounds suggested in comments on the issue above, but they don't appear to work in all cases.

My testing reveals that the problem does not occur in Android 2.3.3 on my Nexus One phone (when using a Bluetooth keyboard with soft input disabled), and it does occur in Android 4.3 on my Nexus 7 tablet in the same situation. This is consistent with the comments on the issue linked above, which indicate that the problem was experienced for Android 4.0 and up.

One commenter on that issue reports that invoking setTextIsSelectable() fixes the problem, and the Javadoc for this method shows that it is available at API level 11 and up. This means that it should be available on all devices exhibiting the problem (since 4.0 starts at API 15).

Therefore, one possible approach would be to use reflection to test for this method (or just test the API for a level >= 11), and invoke the method if it is available on the device. To do this, you would have to compile to an API >= 11 (Project / Properties / Android / Project Build Target in Eclipse - probably just the latest API would work best) and would have to set targetSdkVersion in your manifest file to at least 11 (again, matching the API against which you compiled would probably be best).

See this answer for more information regarding the selective use of features that are available at some, but not all, of the API levels an app is declared as supporting:

Difference between "Build Target SDK" in Eclipse and android:targetSdkVersion in AndroidManifest.xml?

I have not tried this approach yet, but intend to eventually. In the meantime, if anyone else tries it, please add a comment below indicating whether or not that is a good workaround.

Upvotes: 2

Aditya Nikhade
Aditya Nikhade

Reputation: 1371

setCursorVisible(true) this can show the cursor!

android:cursorVisible="false"

Upvotes: 0

Related Questions