您好,登錄后才能下訂單哦!
怎么在Android中使用Toast實現(xiàn)全屏顯示?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
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(); }
根據(jù)實際情況,在toastView添加不同view能顯示不同彈窗,希望對大家有幫助!
另一段自定義toast全屏顯示實現(xiàn)代碼:
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可以布局到系統(tǒng)狀態(tài)欄的下面 } if (!mObjectAnimator.isRunning()) { mObjectAnimator.start(); } mGoodToast.show(); } }
看完上述內(nèi)容,你們掌握怎么在Android中使用Toast實現(xiàn)全屏顯示的方法了嗎?如果還想學到更多技能或想了解更多相關內(nèi)容,歡迎關注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。