如何更改 edittext 文本选择手柄的颜色?

lok*_*oki 5 android android-theme android-edittext android-styles

我知道这个问题已经得到解答,但我找不到有效的解决方案。

在 android > lolipop (21) 上,他们有什么方法可以改变我的文本选择手柄的颜色(无需上传新的 png 图像)?

我定义了这种风格

<?xml version="1.0" encoding="utf-8"?>
<resources>

  <style name="AppEditTextStyle" parent="@android:style/Widget.Material.Light.EditText">
    <item name="android:background">@null</item>    
    <item name="android:textCursorDrawable">@null</item> 
    <item name="android:drawableTint">#00ffffff</item>           
  </style>

  <style name="AppTheme" parent="@android:style/Theme.Material.Light.NoActionBar"> 
    <item name="android:editTextStyle">@style/AppEditTextStyle</item>
  </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

但这不起作用,我收到:错误:找不到与给定名称匹配的资源:attr 'android:drawableTint'。

但在文档(https://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableTint)中明确指出 android:drawableTint 存在:(所以我不明白为什么我错过了?

Bru*_*ira 3

在 android lolipop 和更高版本中,手柄颜色是强调色。

我建议阅读以下内容:

选择 - 模式 - 材料设计指南

这是样式行:

<item name="colorAccent">@color/colorAccent</item>
Run Code Online (Sandbox Code Playgroud)

并像这样设置选择颜色:

android:textColorHighlight="@color/colorAccent"
Run Code Online (Sandbox Code Playgroud)

  • 仅当在 Activity 主题中设置时,句柄的“colorAccent”才会起作用 (3认同)