This commit is contained in:
Horis
2024-05-17 21:57:15 +08:00
parent 5336adc035
commit 9e5cefc47c
2 changed files with 9 additions and 13 deletions
@@ -4,17 +4,14 @@ package io.legado.app.utils
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.view.View
import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.cardview.widget.CardView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.BuildConfig import io.legado.app.BuildConfig
import io.legado.app.R import io.legado.app.databinding.ViewToastBinding
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import splitties.views.inflate import splitties.systemservices.layoutInflater
private var toast: Toast? = null private var toast: Toast? = null
@@ -31,14 +28,13 @@ fun Context.toastOnUi(message: CharSequence?, duration: Int = Toast.LENGTH_SHORT
kotlin.runCatching { kotlin.runCatching {
toast?.cancel() toast?.cancel()
toast = Toast(this) toast = Toast(this)
val toastView: View = inflate(R.layout.view_toast)
toast?.view = toastView
val cardView = toastView.findViewById<CardView>(R.id.cv_content)
cardView.setCardBackgroundColor(bottomBackground)
val isLight = ColorUtils.isColorLight(bottomBackground) val isLight = ColorUtils.isColorLight(bottomBackground)
val textView = toastView.findViewById<TextView>(R.id.tv_text) ViewToastBinding.inflate(layoutInflater).run {
textView.setTextColor(getPrimaryTextColor(isLight)) toast?.view = root
textView.text = message cvToast.setCardBackgroundColor(bottomBackground)
tvText.setTextColor(getPrimaryTextColor(isLight))
tvText.text = message
}
toast?.duration = duration toast?.duration = duration
toast?.show() toast?.show()
} }
+1 -1
View File
@@ -6,7 +6,7 @@
android:orientation="vertical"> android:orientation="vertical">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/cv_content" android:id="@+id/cv_toast"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardCornerRadius="10dp" app:cardCornerRadius="10dp"