gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:29:27 43 4
gpt4 key购买 nike

enter image description here

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

最佳答案

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

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

关于android - 如何更改编辑文本时出现的箭头颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17721399/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com