Android Edittext cursor invisible

2019-06-19 05:00发布

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?

3条回答
Melony?
2楼-- · 2019-06-19 05:47

Try setting your targetSdkVersion to API level 13 or higher to gain access to the android:textCursorDrawable property

查看更多
SAY GOODBYE
3楼-- · 2019-06-19 05:49

If you not has a cursor I guess the input is simple and say you only can enter new chars at end of the text?

I think you can use a TextView and to this add you own KeyListener? But in this case you will has problem with the virtual keyboard not is show, see some of this links:

Forcing the Soft Keyboard open

android force keyboard visible

or create you own keyboard if the rang of valid keys is very limit as only digits.

查看更多
萌系小妹纸
4楼-- · 2019-06-19 05:56

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.

查看更多
登录 后发表回答