微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐