我在平板电脑项目上使用Android的Holo主题时遇到了这个问题。然而,我在屏幕上有一个片段,它有一个白色背景。我在这个片段上添加了一个EditText组件。我试图通过设置Holo的背景来覆盖主题。轻主题资源。然而,我的文本光标(carat)仍然是白色的,因此在屏幕上不可见(我可以在edittext字段中隐约发现它..)。

有人知道如何让EditText使用更深的光标颜色吗?我已经尝试将EditText的样式设置为“@android:style/Widget.Holo.Light”。没有积极的结果。


当前回答

其实比这更简单。

<style name="MyTextStyle">
    <item name="android:textCursorDrawable">#000000</item>
</style>

这适用于ICS和其他领域。我还没有在其他版本中测试过。

其他回答

你想要特定的颜色,你必须使用AppCompatEditText然后backround设置null

对我有用

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

看看这个要点

唯一有效的答案应该是改变活动的主题: <项目名称= " colorAccent " > # 000000 > < /项目 你不应该使用android:textCursorDrawable @null,因为这只关心光标本身,而不是针下面的光标,如果你想拖动该光标。主题化解决方案是最重要的解决方案。

似乎所有的答案都在灌木丛中流传。

在你的EditText中,使用属性:

android:textCursorDrawable="@drawable/black_cursor"

并添加可绘制的black_cursor.xml到您的资源,如下所示:

<?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>

如果需要,这也是创建更多样化游标的方法。

设置android:textCursorDrawable属性为@null应该导致使用android:textColor作为光标颜色。

属性“textCursorDrawable”在API级别12及更高级别可用

<style name="CustomTheme" parent="AppTheme">
    <item name="colorAccent">@color/yourColor</item>
</style>

将其添加到样式中,然后在Edittext中设置主题,如下所示:

android:theme="@style/CustomTheme"

就是这样!