优化搜索文字颜色

pull/379/head
gedoor 4 years ago
parent 65190d6fce
commit 0bffc3e4f3
  1. 11
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchResult.kt

@ -1,9 +1,11 @@
package io.legado.app.ui.book.searchContent package io.legado.app.ui.book.searchContent
import android.text.Spanned import android.text.Spanned
import android.util.Log
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.App
import io.legado.app.R
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.hexString
data class SearchResult( data class SearchResult(
var index: Int = 0, var index: Int = 0,
@ -26,9 +28,10 @@ data class SearchResult(
fun colorPresentText(position: Int, center: String, targetText: String): String { fun colorPresentText(position: Int, center: String, targetText: String): String {
val sub1 = text.substring(0, position) val sub1 = text.substring(0, position)
val sub2 = text.substring(position + center.length, targetText.length) val sub2 = text.substring(position + center.length, targetText.length)
return "<font color=#000000>$sub1</font>" + val textColor = App.INSTANCE.getCompatColor(R.color.primaryText).hexString
return "<font color=#${textColor}>$sub1</font>" +
"<font color=#ff0000>$center</font>" + "<font color=#ff0000>$center</font>" +
"<font color=#000000>$sub2</font>" "<font color=#${textColor}>$sub2</font>"
} }
fun parseText(targetText: String): Spanned { fun parseText(targetText: String): Spanned {

Loading…
Cancel
Save