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

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


当前回答

我们可以在材料主题上做如下:

<style name="Theme.App" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    ...
    <item name="android:colorControlNormal">#ff0000</item>
    <item name="android:colorControlActivated">#ff0000</item>
    <item name="android:colorControlHighlight">#ff0000</item>
    ...
</style>

如果你也想改变复选框和单选颜色,添加下面的行:

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

我已经在Android API 21+中进行了测试

其他回答

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item> -- change this one
</style>

转到styles.xml并更改颜色重音,这将影响编辑文本框的光标

Edittext cursor color you want changes your color.
   <EditText  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textCursorDrawable="@drawable/color_cursor"
    />

然后创建可绘制的xml: color_cursor

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <size android:width="3dp" />
    <solid android:color="#FFFFFF"  />
</shape>

注意你当前活动/片段/对话框中的colorAccent,在Styles中定义…;) 光标颜色与之相关。

哇,我真的很晚才参加这个派对,但它在17天前就有活动了 我们需要考虑发布我们使用的Android版本的答案,所以目前这个答案适用于Android 2.1及以上版本 转到RES/VALUES/STYLES,添加下面的代码行,你的光标将是黑色的

    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!--<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">-->
    <!-- Customize your theme here. -->
    <item name="colorControlActivated">@color/color_Black</item>
    <!--Sets COLOR for the Cursor in EditText  -->
</style>

你需要在RES/COLOR文件夹中有这一行代码

<color name="color_Black">#000000</color>

为什么这么晚才发?Android已经变成了一头怪物,考虑一些分类形式可能会很好!

其实比这更简单。

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

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