6

I have an application that uses an internal ime (meaning the ime is just code within the application and not a true ime). I use this ime panel to enter/edit an editText. Everything works fine up to Froyo (I have not tested under Gingerbread). On Honeycomb, however, I can input text and edit it but no cursor or text highlight is displayed! Does anyone know how to work around this? I'd rather not fork my code to a special Honeycomb version just to correct this one problem.

I have explicitly set the xml cursorVisible element to true and then set it to true with setCursorVisible in the code but that doesn't help.

Thanks!

Programmer Bruce
  • 64,977
  • 7
  • 99
  • 97
Vic
  • 5,977
  • 2
  • 22
  • 19
  • Update: I have now tried the app in Gingerbread and it works properly there as well. The problem is limited to all honeycomb versions to 3.2. – Vic Jul 21 '11 at 18:29
  • Are you setting the input type to 0 (TYPE_NULL)? If so, I do have a workaround that can help you. – Mark D Mar 22 '12 at 19:51

2 Answers2

7

Add these attributes to your EditText, to make the blinking cursor black:

android:textColor="#000000"
android:textCursorDrawable="@null"

It's needed if you're using the Holo theme. From: https://stackoverflow.com/a/9165217/1267112

Community
  • 1
  • 1
Jimmy
  • 221
  • 3
  • 6
0

You can try the code snip below.

public static void setCursorVisible(EditText editText, Context context) {
    editText.setCursorVisible(true);
    // sdk
    // http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
    if (android.os.Build.VERSION.SDK_INT >= 12) {// Android 3.1.x  API12
                                                    // HONEYCOMB_MR1
        String filedNameString = "mCursorDrawableRes";
        // mCursorDrawableRes
        Class<? extends EditText> editTextClass = editText.getClass();
        Class<? extends TextView> textViewClass = null;
        if (editTextClass != null) {
            textViewClass = (Class<? extends TextView>) editTextClass
                    .getSuperclass();
        }
        if (textViewClass != null) {
            Field mCursorDrawableField = null;
            try {
                mCursorDrawableField = textViewClass
                        .getDeclaredField(filedNameString);
            } catch (NoSuchFieldException e) {
                // TODO Auto-generated catch block
                Log.i(TAG, "NoSuchFieldException");
                e.printStackTrace();
            }
            if (mCursorDrawableField != null) {
                mCursorDrawableField.setAccessible(true);
                try {
                    mCursorDrawableField.set(editText, 0);

                } catch (IllegalArgumentException e) {
                    Log.i(TAG, "IllegalArgumentException");
                    e.printStackTrace();
                } catch (NotFoundException e) {
                    Log.i(TAG, "NotFoundException");
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    Log.i(TAG, "IllegalAccessException");
                    e.printStackTrace();
                }
            }

        }
    }
RxRead
  • 3,470
  • 2
  • 17
  • 23