如何更改EditText句柄的颜色? [英] How to change color of EditText handles?

查看:97
本文介绍了如何更改EditText句柄的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绿色是从哪里来的?我尝试更改accentColor属性,该属性可在应用程序的其他部分使用,但不能在此处使用.

Where does the green color comes from? I've tried changing the accentColor attribute, which works in other parts of the app, but not here.

Lollipop中应用程序的屏幕截图.

Screenshot from app in Lollipop.

如何更改以下颜色:

  • 文字处理可绘制对象?如何给它们着色?
  • 全选背景色?

也许还有一些未来的提示...您如何找到答案的?我遇到了所有这些令人困惑的颜色/样式问题.某处是否有某种列表可以告诉我,我需要为特定组件覆盖哪种默认颜色或属性?

And maybe some tips for the future... How did you find out? I've been coming across all these confusing color/styling problems. Is there some kind of list somewhere that tells me, which default color or attribute that I need to overwrite for a certain component?

推荐答案

要更改手柄颜色,您可以按此处进行操作您可以将样式用作

For changing the handle color you can do as specified here you do it using style as

<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>

要以编程方式执行此操作,请在另一个问题此处中通过反射检查相同的问题

For doing it programmatically check same question another reply here which is done using reflection

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设置为

For changing the selected text color you can set textColorHighlight in xml as

android:textColorHighlight="#ff0000"

通过样式,您可以按照

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

这篇关于如何更改EditText句柄的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆