1

在此处输入图像描述

我想更改在 EditText 中编辑文本时出现的箭头颜色,我不知道这些箭头的名称,我该怎么做?

4

2 回答 2

1

您可以通过使用自定义主题并设置以下内容来完成此操作:

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

或者,您可以使用反射:

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) {
}
于 2014-12-05T00:52:19.670 回答
0

我不认为你可以在不改变键盘布局的情况下改变它,这必须单独完成,这里有一些关于如何做到这一点的教程:

链接1

链接2

链接3

链接4

链接5

链接6

编辑:

对于提示颜色,您还可以设置红色,例如,看看这是否有效:

android:textColorHint="#FF0000"
于 2013-07-18T10:59:05.043 回答