我设置了我的 toast 的重力,让它显示在屏幕的顶部,代码如下:
Toast toast = Toast.makeText(getActivity(), "邮箱地址不能为空!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();
它在我的带有 LogCat 消息的 AVD Nexus 6 API 30 中不起作用:E/Toast: setGravity() shouldn't be called on text toasts, the values won't be used
但是,当我在装有 Android 9 的手机诺基亚 X6 上安装 apk 时,它似乎很好。请帮我!!
最佳答案
正如它在关于 Toast 的 Android 文档中所说的 设置重力 方法,此方法不再适用于运行 的设备API30 或更高。我想你有 目标SDK 为您的项目设置为 30。
Warning: Starting from Android Build.VERSION_CODES#R, for apps targeting API level Build.VERSION_CODES#R or higher, this method is a no-op when called on text toasts.
消息来源:https://developer.android.com/reference/android/widget/Toast#setGravity(int,%20int,%20int)
关于java - Toast.setGravity() 在我的 AVD Nexus 6 API 30 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65004242/