Android Toast实现全屏显示
本文为大家分享了AndroidToast全屏显示的具体代码,供大家参考,具体内容如下
废话不说,直接上代码:
privatevoidtoastFullScreen(){ Toasttoast=Toast.makeText(this,null,Toast.LENGTH_LONG*10*1000); toast.setGravity(Gravity.CENTER,0,0); LinearLayouttoastView=(LinearLayout)toast.getView(); //Getthescreensizewithunitpixels. WindowManagerwm=(WindowManager)getSystemService(Context.WINDOW_SERVICE); DisplayMetricsoutMetrics=newDisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); TextViewtv=newTextView(this); LayoutParamsvlp=newLayoutParams(outMetrics.widthPixels, outMetrics.heightPixels); vlp.setMargins(0,0,0,0); tv.setLayoutParams(vlp); tv.setText("HelloToast!Iamfullscreennow."); tv.setGravity(Gravity.CENTER); toastView.addView(tv); toast.show(); }
根据实际情况,在toastView添加不同view能显示不同弹窗,希望对大家有帮助!
另一段自定义toast全屏显示实现代码:
publicclassMyToast{ privatestaticToastmGoodToast; privatestaticObjectAnimatormObjectAnimator; publicstaticvoidshowGoodToast(Contextcontext){ if(mGoodToast==null){ mGoodToast=newToast(context); mGoodToast.setGravity(Gravity.CENTER,0,0); mGoodToast.setDuration(Toast.LENGTH_LONG); Viewview=LayoutInflater.from(context).inflate(R.layout.dialog_good,null,false); AppCompatImageViewimageView=view.findViewById(R.id.shine); mObjectAnimator=ObjectAnimator.ofFloat(imageView,"rotation",5000); mObjectAnimator.setInterpolator(newLinearInterpolator()); 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(); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。