AndroidUtilCode toast在Android 12 出现从A页面跳转至B页面,在B页面一直显示不消失

mmvthczy  于 2022-10-21  发布在  Android
关注(0)|答案(3)|浏览(210)

描述 Bug

最近有部一加的新机型上使用toast工具类出现的bug,在A页面弹的toast,再跳转到B页面后,toast一直存在不消失,主动退出B页面和页面一起消失。

  • AndroidUtilCode 的版本:utilcodex:1.31.0
  • 出现 Bug 的设备型号:onePlus9
  • 设备的 Android 版本:API31

xdnvmnnf

xdnvmnnf1#

Android12设备自定义toast无法显示图标

AndroidUtilCode 的版本:'com.blankj:utilcodex:1.30.5'
出现 Bug 的设备型号:onePlus9
设备的 Android 版本:API31

Toast布局代码:

<?xml version="1.0" encoding="utf-8"?> <com.noober.background.view.BLTextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="34dp" android:drawableStart="@mipmap/ic_points_toast" android:drawablePadding="@dimen/helper.dp.4" android:gravity="center_vertical" android:paddingStart="@dimen/helper.dp.12" android:paddingTop="@dimen/helper.dp.6" android:paddingEnd="@dimen/helper.dp.12" android:paddingBottom="@dimen/helper.dp.6" android:textColor="@color/white" android:textSize="@dimen/helper.sp.14" app:bl_corners_radius="8dp" app:bl_solid_color="@color/color_b3000000" tools:text="100"> </com.noober.background.view.BLTextView>

显示Toast代码

` /**

  • 签到成功
    */
    @SuppressLint("SetTextI18n", "InflateParams")
    fun pointsSignSuccess(pointsBean: PointsBean) {
    //显示自定义toast
    val tvToast = LayoutInflater.from(mActivity).inflate(R.layout.toast_view, null) as TextView
    tvToast.text = "每日签到+${pointsBean.score}"
    val toast = ToastUtils.make()
    toast.setDurationIsLong(true)
    toast.show(tvToast)
//跳转积分界面
    ActivityUtils.startActivity(PointsDetailActivity::class.java)
}`
pxyaymoc

pxyaymoc2#

大佬们要不要封装个snakebar的工具类。toast在高版本上有很多不支持的地方了,比如居中就不不支持了

ia2d9nvy

ia2d9nvy3#

Android12设备自定义toast无法显示图标

AndroidUtilCode 的版本:'com.blankj:utilcodex:1.30.5' 出现Bug 的设备型号:onePlus9 设备的 Android 版本:API31

吐司布局代码:<?xml version="1.0" encoding="utf-8"?> <com.noober.background.view.BLTextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="34dp" android:drawableStart="@mipmap/ic_points_toast" android:drawablePadding="@dimen/helper.dp.4" android:gravity="center_vertical" android:paddingStart="@dimen/helper.dp.12" android:paddingTop="@dimen/helper.dp.6" android:paddingEnd="@dimen/helper.dp.12" android:paddingBottom="@dimen/helper.dp.6" android:textColor="@color/white" android:textSize="@dimen/helper.sp.14" app:bl_corners_radius="8dp" app:bl_solid_color="@color/color_b3000000" tools:text="100"> </com.noober.background.view.BLTextView>

显示Toast代码` /***签到成功 */ @SuppressLint("SetTextI18n", "InflateParams") fun pointsSignSuccess(pointsBean: PointsBean) { //显示自定义toast val tvToast = LayoutInflater.from(mActivity).inflate(R.layout.toast_view, null) as TextView tvToast.text = "每日签到+${pointsBean.score}" val toast = ToastUtils.make() toast.setDurationIsLong(true) toast.show(tvToast)

//跳转积分界面
    ActivityUtils.startActivity(PointsDetailActivity::class.java)
}`

toast不支持自定义布局,你可以使用SpannableString

相关问题