如何制作自定义Toast消息占据整个屏幕

发布于 2024-12-09 04:21:05 字数 805 浏览 0 评论 0原文

我为自定义 toast 消息创建了布局,并将 fill_parent 设置为自定义布局的根元素,但布局的大小仍然比整个屏幕小很多。

是否可以设置 toast 消息的大小以占据整个屏幕?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/toast_layout_root"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical" android:gravity="center" >
    <ImageView android:id="@+id/image"
               android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margin="10dip"/>
</LinearLayout>

请注意 android:layout_width="fill_parent" 和 android:layout_height="fill_parent" 属性。但我的布局仍然大约是屏幕的三分之一。 。 。

有什么想法或建议如何让吐司占据整个屏幕吗?

I created layout for my custom toast message, and I set fill_parent to the root element of my custom layout but the size of the layout is still a lot smaller than the whole screen.

Is it possible to set the size of the toast message to take the whole screen ?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/toast_layout_root"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical" android:gravity="center" >
    <ImageView android:id="@+id/image"
               android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_margin="10dip"/>
</LinearLayout>

Note the android:layout_width="fill_parent" and android:layout_height="fill_parent" properties. But still my layout is around one third of the screen . . .

any ideas or suggestions how can I make the toast to take the whole screen ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

椒妓 2024-12-16 04:21:05
toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.FILL_VERTICAL, 0, 0);
toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.FILL_VERTICAL, 0, 0);
等数载,海棠开 2024-12-16 04:21:05

认为您需要在调用 toast 时进行设置:

Toast myToast = Toast.makeText(this, "Hello", Toast.LENGTH_SHORT);
myToast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);

无法准确记住需要将管道字符放在哪里,然后添加 Gravity.FILL_VERTICAL。

Think you need to set this when calling the toast:

Toast myToast = Toast.makeText(this, "Hello", Toast.LENGTH_SHORT);
myToast.setGravity(Gravity.FILL_HORIZONTAL, 0, 0);

Can't remember exactly where you would need to put the pipe character to then add Gravity.FILL_VERTICAL.

呢古 2024-12-16 04:21:05

看一下这行 toast.setGravity(Gravity.FILL,0,0),它使 toast 按照您想要的方式填充整个屏幕。这是我用于自定义吐司的内容,我想将其填满整个屏幕。

fun showCorectAnswerToast() {
    val inflater = layoutInflater
    val layout = inflater.inflate(R.layout.custom_toast,
        view?.findViewById<View>(R.id.custom_toast_container) as ViewGroup?)
    val toast = Toast(context)
    toast.setGravity(Gravity.FILL,0,0)
    toast.duration = Toast.LENGTH_SHORT
    toast.view = layout
    toast.show()
}

Look at this line toast.setGravity(Gravity.FILL,0,0), it makes the toast fill the whole screen just as you want. It is what I use for custom toasts, which I would like to fill the whole screen.

fun showCorectAnswerToast() {
    val inflater = layoutInflater
    val layout = inflater.inflate(R.layout.custom_toast,
        view?.findViewById<View>(R.id.custom_toast_container) as ViewGroup?)
    val toast = Toast(context)
    toast.setGravity(Gravity.FILL,0,0)
    toast.duration = Toast.LENGTH_SHORT
    toast.view = layout
    toast.show()
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文