From 2c88b4271d438c69dde0944f2d2915ac1840832a Mon Sep 17 00:00:00 2001 From: ocean <503259349@qq.com> Date: Thu, 16 Oct 2025 18:18:15 +0800 Subject: [PATCH] update --- .../PdfPasswordProtectionDialogFragment.kt | 36 ++++++++++++++++++- .../layout/dialog_pdf_password_protection.xml | 1 - 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/all/pdfreader/pro/app/ui/dialog/PdfPasswordProtectionDialogFragment.kt b/app/src/main/java/com/all/pdfreader/pro/app/ui/dialog/PdfPasswordProtectionDialogFragment.kt index a6c09b1..0919ffe 100644 --- a/app/src/main/java/com/all/pdfreader/pro/app/ui/dialog/PdfPasswordProtectionDialogFragment.kt +++ b/app/src/main/java/com/all/pdfreader/pro/app/ui/dialog/PdfPasswordProtectionDialogFragment.kt @@ -2,9 +2,17 @@ package com.all.pdfreader.pro.app.ui.dialog import android.graphics.Color import android.os.Bundle +import android.text.Html +import android.text.Spannable +import android.text.SpannableString +import android.text.style.ForegroundColorSpan import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TextView +import androidx.annotation.ColorInt +import androidx.annotation.StringRes +import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.toDrawable import androidx.fragment.app.DialogFragment import com.all.pdfreader.pro.app.R @@ -50,7 +58,12 @@ class PdfPasswordProtectionDialogFragment( if (isPrompt) { binding.promptTv.visibility = View.VISIBLE - binding.promptTv.text = getString(R.string.file_is_password_protected, file.name) + val color = ContextCompat.getColor(requireContext(), R.color.icon_sel_on_color) + binding.promptTv.setColoredPlaceholder( + R.string.file_is_password_protected, + file.name, + color + ) } else { binding.promptTv.visibility = View.GONE } @@ -73,4 +86,25 @@ class PdfPasswordProtectionDialogFragment( } } } + + fun TextView.setColoredPlaceholder( + @StringRes resId: Int, // 字符串资源 ID + placeholderText: String, // 要染色的占位符文字 + @ColorInt color: Int // 颜色 + ) { + val fullText = context.getString(resId, placeholderText) + val start = fullText.indexOf(placeholderText) + val end = start + placeholderText.length + + val spannable = SpannableString(fullText) + spannable.setSpan( + ForegroundColorSpan(color), + start, + end, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + ) + + text = spannable + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_pdf_password_protection.xml b/app/src/main/res/layout/dialog_pdf_password_protection.xml index cc91244..775e7ed 100644 --- a/app/src/main/res/layout/dialog_pdf_password_protection.xml +++ b/app/src/main/res/layout/dialog_pdf_password_protection.xml @@ -23,7 +23,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" - android:text="@string/file_is_password_protected" android:textColor="@color/black" android:textSize="14sp" android:visibility="gone" />