android - 如何更改我的其中一个 EditText 的文本选择 handle 的颜色?

标签 android android-edittext textview android-theme android-styles

我有一些 EditText 放在蓝色背景上,对于这些 EditText,我想为文本选择 handle 设置白色(如果可能的话,在 Lollipop 或更新版本上不上传新的 png 图像)

enter image description here

我尝试添加 <item name="android:colorAccent">#ffffffff</item>按照我的自定义 EditText 的样式,如下所示:

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

  <!-- EditText on a blue background -->
  <style name="BlueBGTextView" parent="@android:style/Widget.Material.Light.EditText">
    <item name="android:background">@null</item> <!-- this will also remove all paddings -->  
    <item name="android:textCursorDrawable">@null</item> <!-- this to use android:textColor as the cursor color. -->  
    <item name="android:colorAccent">#ffffffff</item> 
  </style>

  <!-- default EditText -->
  <style name="AppTheme.EditTextStyle" parent="@android:style/Widget.Material.Light.EditText">
    <item name="android:background">@null</item> <!-- this will also remove all paddings -->  
  </style>

  <!-- default Theme -->
  <style name="AppTheme" parent="@android:style/Theme.Material.Light.NoActionBar"> 
    <item name="android:editTextStyle">@style/AppTheme.EditTextStyle</item>
    <item name="android:colorAccent">#ff0288d1</item> <!-- use to setup the color of the text selection handles -->   
    <item name="@attr/BlueBGTextViewStyle">@style/BlueBGTextView</item>
  </style>

</resources>

但它不起作用 :( 我错过了什么?

最佳答案

您可以在 xml 中指定 textColorHighlight 属性

示例

android:textColorHighlight="#ff0000"

要更改句柄,请使用 colorControlActivated 属性定义样式

<style name="BlueBGTextView">
    <item name="colorControlActivated">@android:color/black</item>
</style>

并将其设置为您的 EditText

的主题
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/BlueBGTextView"/>

关于android - 如何更改我的其中一个 EditText 的文本选择 handle 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44197546/

相关文章:

Android GMS 库抛出 IllegalArgumentException : Unexpected number of IObjectWrapper declared fields: 3

Android - 未找到处理 Intent 的 Activity { act=android.intent.action.VIEW - 尝试打开 PDF 文件

android - 通过 Wireshark 实时捕获 Android 蓝牙流量

java - 带有芯片的 Android AutoCompleteTextView

android - EditText 如何只接受整数或浮点值?

Android TextView内存泄漏

java - 从 ListView 中隐藏/显示 ImageView

java - EditText.getText().toString() 崩溃

Android TextView 文本未在版本 2.3.3 的 RelativeLayout 中换行

android - 从 Textview 获取值(value)