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

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


当前回答

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

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

android:theme="@style/CustomTheme"

就是这样!

其他回答

在最新的Appcompact v21中,有一种改变光标颜色的新方法 只需要改变颜色,就像这样:

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->

    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#088FC9</item>

    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#088FC9</item>

    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <!-- THIS IS WHAT YOU'RE LOOKING FOR -->
    <item name="colorAccent">#0091BC</item> 
</style>

然后将此样式应用于应用主题或活动。

更新:这种方法只适用于API 21+ 更新2:我不确定它可以工作的最低安卓版本。android版本测试:

2.3.7 - didn't work
4.4.4 - worked
5.0 - worked
5.1 - worked

你可以在布局中使用下面的代码

android:textCursorDrawable="@color/red"
        android:textColor="@color/black

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

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

对我有用

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

看看这个要点

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

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

android:theme="@style/CustomTheme"

就是这样!