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

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


当前回答

在Android中叫做colorAccent。

转到res -> values -> styles.xml添加

<item name="colorAccent">#FFFFFF</item>

If不存在。

其他回答

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

对我有用

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

看看这个要点

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

在你的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>

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

对我来说,我修改了AppTheme和一个值colors.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorControlNormal">@color/yellow</item>
    <item name="colorAccent">@color/yellow</item>
</style>

这是colors.xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="yellow">#B7EC2A</color>
</resources>

我拿出了android:textCursorDrawable属性@null,我放置在editText样式。当我尝试使用这个,颜色不会改变。

在最新的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属性为@null应该导致使用android:textColor作为光标颜色。

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