getActivity / Toaster

Android 吐司框架,专治 Toast 各种疑难杂症
Apache License 2.0
3.2k stars 404 forks source link

Gravity.BOTTOM or Gravity.FILL_HORIZONTAL 无法全屏 #107

Closed trycatchx closed 1 year ago

trycatchx commented 1 year ago

问题描述 框架版本【必填】:12.2

复现步骤【必填】:在android12的小米手机上。显示较短的 toast

是否必现【必填】:是

出现问题的手机信息【必填】:android12 的全部手机

出现问题的安卓版本【必填】: Android 12,api 31

问题信息的来源渠道【必填】:自己在android12的小米手机上集成Toaster看到的

请回答 是部分机型还是所有机型都会出现【必答】:全部

框架最新的版本是否存在这个问题【必答】:是

是否已经查阅框架文档但还未能解决的【必答】:是

issue 是否有人曾提过类似的问题【必答】:否

是否可以通过 Demo 来复现该问题【必答】:是

使用原生的 Toast 是否也会出现该问题【必答】:否

代码:

   Toaster.init(context as Application)
        Toaster.setGravity(Gravity.BOTTOM or Gravity.FILL_HORIZONTAL, 0, PxConvert.dp2px(120f))
        Toaster.setView(R.layout.toast_custom_layout)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal">
    <libbaseui.view.RoundLinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        app:radius="@dimen/dp_100">

        <TextView
            android:id="@android:id/message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/color_363839"
            android:paddingHorizontal="24dp"
            android:paddingVertical="7dp"
            android:textColor="@color/color_80_FFFFFF"
            android:gravity="center_horizontal"
            android:textSize="14dp"
            tools:text="toast弹窗提示" />
    </libbaseui.view.RoundLinearLayout>
</FrameLayout>
trycatchx commented 1 year ago

目前我通过引入 源码修改了: ToastImpl 中的 mShowRunnable : params.width = WindowManager.LayoutParams.MATCH_PARENT;

trycatchx commented 1 year ago

目前暂时解决了这个问题。但是可能对通用性是否有一定的影响

getActivity commented 1 year ago

小伙子,目前 Toast 的 WindowManager 的宽度只能是自适应的,不能被占满,你可以考虑使用悬浮窗框架来处理这个场景,目前 XToast 支持设置窗口宽度和高度