android toast全屏,Android Toast实现全屏显示

2022-09-30 10:27:45 浏览数 (2)

大家好,又见面了,我是你们的朋友全栈君

本文为大家分享了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();

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

时间: 2018-08-25

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/194312.html原文链接:https://javaforall.cn

0 人点赞