如何更改编辑文本时出现的箭头颜色

时间:2013-07-18 10:49:36

标签: android android-edittext

enter image description here

我想更改在EditText中编辑文本时出现的箭头颜色,我不知道这些箭头的名称, 我怎样才能做到这一点 ?

2 个答案:

答案 0 :(得分: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) {
}

答案 1 :(得分:0)

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

LINK1

LINK2

LINK3

LINK4

LINK5

LINK6

编辑:

对于提示颜色,你也可以设置一个红色,例如,看看这是否有效:

android:textColorHint="#FF0000"
相关问题