2011-04-29 76 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(); 
       } 
      } 

     } 
    }