change edittext cursor color

Viewed 74832

How can I change EditText's cursor's color programmatically ?

In android 4.0 and above, cursor color is white. and if EditTexts background is also white, it becomes invisible.

8 Answers

Set Via AppTheme

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"><!-- Customize your theme here. -->
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:spinnerStyle">@style/spinner_style</item>
    <!--Add This-->
    <item name="editTextStyle">@style/EdittextStyle</item>
    <item name="android:dropDownListViewStyle">@style/SpinnerStyle</item>
</style>

<!--New EditText Style-->
<style name="EdittextStyle" parent="Widget.AppCompat.EditText">
    <item name="android:background">?attr/editTextBackground</item>
    <item name="android:textColor">?attr/editTextColor</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
    <!--<item name="android:textCursorDrawable">@drawable/abc_text_cursor_material</item>-->
    <item name="colorControlNormal">@color/colorAccent</item>
    <item name="colorControlActivated">@color/colorAccent</item>
    <item name="colorControlHighlight">@color/colorAccent</item>

</style>
Related