How to change color / appearance of EditText select handle / anchor?

前端 未结 6 1397
不思量自难忘°
不思量自难忘° 2020-11-27 17:46

So I changed the style of the Holo Theme with the Holo Colors Generator and Action Bar Style Generator to my own color. But when I select text inside an edit text, the \"mar

6条回答
  •  孤街浪徒
    2020-11-27 18:06

    How to do it from code:

    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) {
    }
    

提交回复
热议问题