Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Edittext cursor invisible

I have an edittext in my application that will show the cursor correctly in Froyo or Gingerbread, however in later sdks the cursor is invisible. I have found online the solution is to set the android:textCursorDrawable="@null" so that the edittext will use the font color for the cursor. However, since my minsdkversion is 8, I do not have access to that property.

Is their either a way to selectively add a property based on the sdk you are on? Or possibly a way to work around this so that I can have visible cursors on both older and newer sdk versions?

like image 473
Michaeldcooney Avatar asked Aug 31 '12 21:08

Michaeldcooney


1 Answers

I don't know your current setup, but one way to use that property is to use different layouts folders based on various android versions. android:textCursorDrawable is a property introduced in API 12 so you could have a layout folder like layout-v12 which will be used where the API is 12 or greater. In the layouts from this folder the use of the property is valid. For lower versions, Froyo and Gingerbread, you don't have any problems so you would use a default folder, layout. In the end you'll have two layouts folder(containing the same layout files):

layout // don't need the property
layout-v12 // use the property

That leaves out API 11, I don't know if this is a deal breaker for you.

like image 139
user Avatar answered Nov 19 '22 19:11

user