Android Edit Text Cursor does not appear

in my application, I disabled the keyboard (now I use my custom keyboard) with this code:

editText.setInputType(InputType.TYPE_NULL); 

Now my problem is that the text cursor no longer appears in the edit text. What should I do? Any suggestion would be greatly appreciated.

+6
source share
4 answers

To do this, there is a problem open in the Issue error tracker , open to track errors . One user offers an approach that works on the "majority" of devices.

In short, all you have to do is call:

 editText.setRawInputType(InputType.TYPE_CLASS_TEXT); 

for your view EditText (after calling editText.setInputType(InputType.TYPE_NULL); ).

You should probably also install:

 editText.setTextIsSelectable(true); 

so that the text can be selected (although it does not seem to work properly with the Samsung Galaxy SIII). This method is only available with HONEYCOMB (api11), so keep this in mind when developing for older versions of Android.

It is also pointed out that your EditText should not be the first view to get focus when starting an activity (if it is just requestFocus () from another view). Although I (personally) had no problems with this.

+16
source

Instead of just using a custom view for your custom keyboard, why not implement a full-fledged IME? This will solve your cursor problem and even make your keyboard accessible outside your application (if you want).

This answer contains a couple of useful links if you want to do this: How to develop a soft keyboard for Android?

0
source

I really would not suggest this. Writing a full IME is really difficult. In addition, users expect functionality from the keyboard (automatic correction, Swyping, prediction of the next word, the ability to change languages), which you will not have if you do not spend months on the keyboard itself. Any application that does not allow me to use Swype will be removed immediately (offset note: I worked on Swype android).

But if you want to fully integrate with the OS as a keyboard, you will have to write InputMethodService. Then your keyboard will be selected by the user in the keyboard selection menu and used for any application. This is the only way to get full integration with the OS, otherwise you will need to start from scratch to write your own EditView. Enjoy it by getting one that looks beautiful, definitely non-trivial.

In addition, setting the input type to null will not disable most keyboards. It just puts them in silent mode and disables things like prediction.

0
source

I tried the answer below, and it worked, but make sure 1) EditText should not focus on initialization 2) when your orientation changes, when the user focus is on editText, the stock keyboard appears, which is another "solved" problem.

This was mentioned in a previous answer, but be careful that you MUST make sure your editText element does not focus on instantiating:

https://code.google.com/p/android/issues/detail?id=27609#c7

# 7 nyphb ... @ gmail.com

I finally found a working solution for me.

The first part (in onCreate):

 mText.setInputType(InputType.TYPE_NULL); if (android.os.Build.VERSION.SDK_INT >= 11 /*android.os.Build.VERSION_CODES.HONEYCOMB*/) { // this fakes the TextView (which actually handles cursor drawing) // into drawing the cursor even though you've disabled soft input // with TYPE_NULL mText.setRawInputType(InputType.TYPE_CLASS_TEXT); } 

In addition, for android: textIsSelectable, you must set it to true (or set to onCreate), and EditText should not focus on initialization. If your EditText is the first custom view (which was in my case), you can get around this by putting it just above it:

 <LinearLayout android:layout_width="0px" android:layout_height="0px" android:focusable="true" android:focusableInTouchMode="true" > <requestFocus /> </LinearLayout> 
0
source

All Articles