android – 如何更改EditText句柄的颜色?

绿色来自哪里?我已经尝试更改accentColor属性,该属性适用于应用程序的其他部分,但不在此处.

来自Lollipop的应用程序的屏幕截图.

我怎样才能改变颜色:

>文字处理drawables?怎么给他们着色?
>全选背景颜色?

也许是未来的一些提示……你是怎么发现的?我一直在遇到所有这些令人困惑的颜色/造型问题.是否有某种列表告诉我,我需要为某个组件覆盖哪个认颜色或属性

解决方法

要更改手柄颜色,您可以按照指定 here执行,使用样式作为
<style name="MyCustomTheme" parent="@style/MyNotSoCustomTheme">
        <item name="android:textSelectHandle">@drawable/text_select_handle_middle</item>
        <item name="android:textSelectHandleLeft">@drawable/text_select_handle_left</item>
        <item name="android:textSelectHandleRight">@drawable/text_select_handle_right</item>
</style>

为了做它以编程方式检查相同的问题另一个回复here,这是使用反射完成的

try {
    final Field fEditor = TextView.class.getDeclaredField("mEditor");
    fEditor.setAccessible(true);
    final Object editor = fEditor.get(editText);

    final Field fSelectHandleLeft = editor.getClass().getDeclaredField("mSelectHandleLeft");
    final Field fSelectHandleRight = editor.getClass().getDeclaredField("mSelectHandleRight");
    final Field fSelectHandleCenter = editor.getClass().getDeclaredField("mSelectHandleCenter");

    fSelectHandleLeft.setAccessible(true);
    fSelectHandleRight.setAccessible(true);
    fSelectHandleCenter.setAccessible(true);

    final Resources res = context.getResources();

    fSelectHandleLeft.set(editor,res.getDrawable(R.drawable.text_select_handle_left));
    fSelectHandleRight.set(editor,res.getDrawable(R.drawable.text_select_handle_right));
    fSelectHandleCenter.set(editor,res.getDrawable(R.drawable.text_select_handle_middle));
} catch (final Exception ignored) {
}

要更改所选的文本颜色,可以将xml中的textColorHighlight设置为

android:textColorHighlight="#ff0000"

通过你可以做的风格

<item name="android:textColorHighlight">@color/m_highlight_blue</item>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...