pab*_*sco 6 java android android-edittext
我正在使用BackgroundColorSpan突出显示内的某些文本EditText。我遇到的问题是,如果颜色具有100%的alpha值且很难用较低的alpha值查看,则文本字段的光标不可见。
我对EditText和的代码进行了一些挖掘Editor(用于在中绘制文本EditText),并且发现Editor.onDraw(...)在Layout之前先绘制了光标内部(后者又绘制了文本):
if (highlight != null && selectionStart == selectionEnd && mCursorCount > 0) {
>> drawCursor(canvas, cursorOffsetVertical);
// Rely on the drawable entirely, do not draw the cursor line.
// Has to be done after the IMM related code above which relies on the highlight.
highlight = null;
}
if (mTextView.canHaveDisplayList() && canvas.isHardwareAccelerated()) {
drawHardwareAccelerated(canvas, layout, highlight, highlightPaint,
cursorOffsetVertical);
} else {
>> layout.draw(canvas, highlight, highlightPaint, cursorOffsetVertical);
}
Run Code Online (Sandbox Code Playgroud)
有人知道我该如何扭转这种行为?我目前唯一想到的选择是自己画光标或做一些反射伏都教。两者似乎都有些过分。
更新:
我已经在Android问题跟踪器上为此创建了一个错误报告:https : //code.google.com/p/android/issues/detail? id =172001
我最终做的解决方案是创建两个扩展。EditText 之一和BackgroundColorSpan.
的扩展BackgroundColorSpan不会改变TextPaintin的背景颜色updateDrawState(),但它允许外部类访问这种颜色。
EditText 的扩展会查找特殊内容并在调用超级实现之前BackgroundColorSpan手动在内部绘制背景。onDraw()
此要点显示了完整的解决方案(需要创建导入):
https://gist.github.com/pablisco/d9dc57cc2e9dc85d24de
注意:如果保存并恢复了跨度(例如在旋转时),则效果不佳,因此在恢复时可能需要操纵跨度。
| 归档时间: |
|
| 查看次数: |
156 次 |
| 最近记录: |