From f982882f214bfafd1bbda3e9d5a89f278acf2541 Mon Sep 17 00:00:00 2001 From: white-yj8109 <19310195525@163.com> Date: Wed, 21 Jan 2026 09:25:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BF=BB=E8=AF=91=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E5=AD=97=E4=BD=93=E9=A2=9C=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/NoteEditActivity.java | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/ui/NoteEditActivity.java b/src/ui/NoteEditActivity.java index 0c5039e..2a09ae7 100644 --- a/src/ui/NoteEditActivity.java +++ b/src/ui/NoteEditActivity.java @@ -806,12 +806,32 @@ public class NoteEditActivity extends Activity implements OnClickListener, View focused = mEditTextList.getChildAt(index); focused.findViewById(R.id.et_edit_text).requestFocus(); } else { - // 普通模式下,直接显示翻译结果 - mNoteEditor.setText(result); - // scroll to first translation: find first occurrence of "[翻译失败]" or second line - int idx = result.indexOf('\n'); - if (idx >= 0 && idx + 1 < result.length()) { - mNoteEditor.setSelection(idx + 1); + // 普通模式下,直接显示翻译结果 + SpannableString spannable = new SpannableString(result); + // 分析文本结构:原文和翻译交替出现 + // 格式:原文1\n翻译1\n原文2\n翻译2\n... + String[] lines = result.split("\n"); + int currentPosition = 0; + boolean isTranslation = false; + + for (String line : lines) { + if (!TextUtils.isEmpty(line)) { + if (isTranslation) { + // 设置翻译结果为浅灰色 + int start = currentPosition; + int end = currentPosition + line.length(); + spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#999999")), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + isTranslation = !isTranslation; + } + currentPosition += line.length() + 1; // +1 for newline + } + + mNoteEditor.setText(spannable); + // scroll to first translation + int firstTranslationIdx = result.indexOf('\n'); + if (firstTranslationIdx >= 0 && firstTranslationIdx + 1 < result.length()) { + mNoteEditor.setSelection(firstTranslationIdx + 1); } } } else {