Set EditText cursor color

后端 未结 24 1361
醉话见心
醉话见心 2020-11-22 10:57

I am having this issue where I am using the Android\'s Holo theme on a tablet project. However, I have a fragment on screen which has a white background. I am adding an

相关标签:
24条回答
  • 2020-11-22 11:37

    are you want specific color you must use AppCompatEditText then backround set null

    works for me

    <android.support.v7.widget.AppCompatEditText
        android:background="@null"
        android:textCursorDrawable="@color/cursorColor"/>
    

    See this gist

    0 讨论(0)
  • 2020-11-22 11:40

    Setting the android:textCursorDrawable attribute to @null should result in the use of android:textColor as the cursor color.

    Attribute "textCursorDrawable" is available in API level 12 and higher

    0 讨论(0)
  • 2020-11-22 11:40

    In Layout

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

    Then create drawalble xml: color_cursor

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

    You have a white color cursor on EditText property.

    0 讨论(0)
  • 2020-11-22 11:40

    It appears as if all the answers go around the bushes.

    In your EditText, use the property:

    android:textCursorDrawable="@drawable/black_cursor"
    

    and add the drawable black_cursor.xml to your resources, as follows:

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

    This is also the way to create more diverse cursors, if you need.

    0 讨论(0)
  • 2020-11-22 11:40

    Pay attention to your colorAccent in your current Activity/fragment/Dialog, defined in Styles... ;) cursor color is related to it.

    0 讨论(0)
  • 2020-11-22 11:41
    Edittext cursor color you want changes your color.
       <EditText  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textCursorDrawable="@drawable/color_cursor"
        />
    

    Then create drawalble xml: color_cursor

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
        <size android:width="3dp" />
        <solid android:color="#FFFFFF"  />
    </shape>
    
    0 讨论(0)
提交回复
热议问题