绿色从何而来?我试过更改 accentColor
属性,该属性在应用程序的其他部分有效,但在此处无效。
Lollipop 应用程序的屏幕截图。
如何更改颜色:
- 文本句柄drawables?如何给它们上色?
- 全选背景颜色?
也许还有一些关于 future 的建议……你是怎么知道的?我一直遇到所有这些令人困惑的颜色/样式问题。某处是否有某种列表告诉我,我需要为某个组件覆盖哪种默认颜色或属性?
最佳答案
要更改 handle 颜色,您可以按照指定的方式进行 here你使用 style 作为
<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>
关于android - 如何更改 EditText 句柄的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29795197/