这篇文章主要为大家详细介绍了Android Toast实现全屏显示,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文为大家分享了Android Toast全屏显示的具体代码,供大家参考,具体内容如下
废话不说,直接上代码:
private void toastFullScreen(){
Toast toast = Toast.makeText(this, null, Toast.LENGTH_LONG * 10 * 1000);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout toastView = (LinearLayout)toast.getView();
// Get the screen size with unit pixels.
WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
TextView tv = new TextView(this);
LayoutParams vlp = new LayoutParams(outMetrics.widthPixels,
outMetrics.heightPixels);
vlp.setMargins(0, 0, 0, 0);
tv.setLayoutParams(vlp);
tv.setText("Hello Toast! I am full screen now.");
tv.setGravity(Gravity.CENTER);
toastView.addView(tv);
toast.show();
}
根据实际情况,在toastView添加不同view能显示不同弹窗,希望对大家有帮助!
另一段自定义toast全屏显示实现代码:
public class MyToast {
private static Toast mGoodToast;
private static ObjectAnimator mObjectAnimator;
public static void showGoodToast(Context context) {
if (mGoodToast == null) {
mGoodToast = new Toast(context);
mGoodToast.setGravity(Gravity.CENTER, 0, 0);
mGoodToast.setDuration(Toast.LENGTH_LONG);
View view = LayoutInflater.from(context).inflate(R.layout.dialog_good, null, false);
AppCompatImageView imageView = view.findViewById(R.id.shine);
mObjectAnimator = ObjectAnimator.ofFloat(imageView, "rotation", 5000);
mObjectAnimator.setInterpolator(new LinearInterpolator());
mObjectAnimator.setDuration(30000);
mGoodToast.setGravity(Gravity.FILL, 0, 0);
mGoodToast.setView(view);
mGoodToast.getView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);//设置Toast可以布局到系统状态栏的下面
}
if (!mObjectAnimator.isRunning()) {
mObjectAnimator.start();
}
mGoodToast.show();
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:Android Toast实现全屏显示
基础教程推荐
猜你喜欢
- Flutter进阶之实现动画效果(三) 2022-10-28
- MVVMLight项目Model View结构及全局视图模型注入器 2023-05-07
- iOS开发使用XML解析网络数据 2022-11-12
- IOS获取系统相册中照片的示例代码 2023-01-03
- iOS Crash常规跟踪方法及Bugly集成运用详细介绍 2023-01-18
- iOS中如何判断当前网络环境是2G/3G/4G/5G/WiFi 2023-06-18
- Android Compose自定义TextField实现自定义的输入框 2023-05-13
- iOS开发 全机型适配解决方法 2023-01-14
- Android开发Compose集成高德地图实例 2023-06-15
- Android实现短信验证码输入框 2023-04-29