2011-04-29 54 views
6

我有一个应用程序使用内部时间(意味着ime只是应用程序中的代码,而不是真正的时间)。我使用这个面板输入/编辑editText。一切工作正常Froyo(我还没有在姜饼下测试)。但是,在Honeycomb上,我可以输入文本并对其进行编辑,但不显示光标或文本高亮显示!有谁知道如何解决这个问题?我宁愿不将我的代码分发给一个特殊的Honeycomb版本来纠正这个问题。在Honeycomb的editText中没有光标

我已经明确地将xml cursorVisible元素设置为true,然后在代码中将setCursorVisible设置为true,但这没有帮助。

谢谢!

+0

更新:我现在已经尝试过姜饼应用程序,它在那里也正常工作。该问题仅限于所有蜂窝版本为3.2。 – Vic 2011-07-21 18:29:34

+0

您是否将输入类型设置为0(TYPE_NULL)?如果是这样,我确实有一个解决方法可以帮助你。 – 2012-03-22 19:51:49

回答

7

这些属性添加到您的EditText,使闪烁的光标黑色:

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

它,如果你使用的全息主题需要。 来自:https://stackoverflow.com/a/9165217/1267112

+0

另外,android:textCursorDrawable是最小的API 12 – 2013-06-02 22:08:12

0

您可以尝试下面的代码片段。

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(); 
       } 
      } 

     } 
    }