2014-11-17 111 views
3

在我的應用程序中,我使用的光標顏色爲EditText光標在HTC設備的EditText中不可見

它正在工作三星設備但在HTC One它沒有顯示。如果我將textCursorDrawable元素設置爲null,它將顯示默認文本顏色作爲光標顏色,但我需要紅色的光標顏色。

我無法得到確切的問題。 請任何人都可以幫助我。

這是我在XML代碼EditText

<EditText 
    android:id="@+id/username_edit" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_weight="90" 
    android:background="@null" 
    android:ems="10" 
    android:hint="user name" 

    android:maxLength="60" 
    android:paddingLeft="5dp" 
    android:singleLine="true" 
    android:textColor="@color/black" 
    android:textCursorDrawable="@color/appheader_color" 
    android:textSize="@dimen/TextSize_medium" > 

</EditText> 
+0

Android是什麼版本,您正在使用? –

+0

爲我的應用程序我使用minsadVersion是8和最大是19 htc手機版本是4.4.2 –

回答

2

嘗試增加

android:textCursorDrawable="@null" 

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textCursorDrawable="@drawable/color_cursor" 
    /> 

在繪製你可以設置自己的顏色

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <size android:width="1dp" /> 
    <solid android:color="#FFFFFF" /> //#FFFFFF will be replaced by your color code 
</shape> 
+0

如果我添加此光標將可見,但它顯示在文本color.But我需要紅色。 –

+0

感謝它的工作正常。我可以動態添加它嗎? –

+0

這裏引用:https://stackoverflow.com/questions/11554078/set-textcursordrawable-programmatically –

0

試試這個。它可能會幫助你。

創建drawalble XML:cursor_color

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <size android:width="3dp" /> 
    <solid android:color="#FF0000" /> 
</shape> 

在EDITTEXT:

<EditText 
        android:id="@+id/username_edit" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:layout_weight="90" 
        android:background="@null" 
        android:ems="10" 
        android:hint="user name" 

        android:maxLength="60" 
        android:paddingLeft="5dp" 
        android:singleLine="true" 
        android:textColor="@color/black" 
        android:textCursorDrawable="@drawable/cursor_color" 
        android:textSize="@dimen/TextSize_medium" > 


       </EditText> 
+0

感謝它的工作正常。我可以動態地添加它? –

+0

試試這個http://stackoverflow.com/questions/11554078/set-textcursordrawable-in-javacode –