This commit is contained in:
ocean 2025-10-16 18:18:15 +08:00
parent 8504e7cbea
commit 2c88b4271d
2 changed files with 35 additions and 2 deletions

View File

@ -2,9 +2,17 @@ package com.all.pdfreader.pro.app.ui.dialog
import android.graphics.Color import android.graphics.Color
import android.os.Bundle 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.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup 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.core.graphics.drawable.toDrawable
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.all.pdfreader.pro.app.R import com.all.pdfreader.pro.app.R
@ -50,7 +58,12 @@ class PdfPasswordProtectionDialogFragment(
if (isPrompt) { if (isPrompt) {
binding.promptTv.visibility = View.VISIBLE 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 { } else {
binding.promptTv.visibility = View.GONE 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
}
} }

View File

@ -23,7 +23,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:text="@string/file_is_password_protected"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="14sp" android:textSize="14sp"
android:visibility="gone" /> android:visibility="gone" />