Android Toast居中显示方法二

Android Toast居中显示方法一请看 Android Toast设置居中显示方法一-CSDN博客

下面来讲讲第二种方法:

java 复制代码
        Toast toast = Toast.makeText(MainActivity.this, "my toast", Toast.LENGTH_SHORT);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER);
        View toastView = toast.getView();
        toastView.setLayoutParams(layoutParams);
        toast.setGravity(Gravity.CENTER, 0, 0); //居中显示
        toast.show();
相关推荐
白云LDC7 小时前
Android Studio新建Vecter asset一直显示Loading icons(转圈圈)的解决办法
android·ide·android studio
Rytter10 小时前
某气骑士 libtprt.so 反 Frida 机制分析与绕过
android·安全·网络安全
alexhilton11 小时前
揭密:Compose应用如何做到启动提升34%
android·kotlin·android jetpack
沐言人生13 小时前
React Native 源码分析1——HybridData 机制深度分析
android·react native
程序员陆业聪13 小时前
跨平台框架全景图:Flutter/KMP/KuiKly/RN的2026年格局
android
码云数智-园园14 小时前
Fibers(纤程)来了:打破阻塞,实现纯PHP下的异步非阻塞IO
android
shaoming377617 小时前
检查系统硬件配置是否满足PyCharm最低要求
android·spring boot·mysql
一起搞IT吧17 小时前
高通Camx功能feature分析之十五:insensor zoom介绍及实现
android·智能手机·相机
aqi0019 小时前
一文读懂 HarmonyOS 6.1 带来的十大重要升级
android·华为·harmonyos·鸿蒙·harmony
秋921 小时前
MySQL 9.7.0 使用详解:新特性、实战与避坑指南
android·数据库·mysql