You can try the snapshot 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(); } } } }
source share