Android Toast實(shí)現(xiàn)全屏顯示
本文為大家分享了Android Toast全屏顯示的具體代碼,供大家參考,具體內(nèi)容如下
廢話不說(shuō),直接上代碼:
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ù)實(shí)際情況,在toastView添加不同view能顯示不同彈窗,希望對(duì)大家有幫助!
另一段自定義toast全屏顯示實(shí)現(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);//設(shè)置Toast可以布局到系統(tǒng)狀態(tài)欄的下面
}
if (!mObjectAnimator.isRunning()) {
mObjectAnimator.start();
}
mGoodToast.show();
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android中Activity的四種啟動(dòng)模式和onNewIntent()
android 中activity的啟動(dòng)模式分為四種,(standard、singleTop、singTask、singleInstance),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-08-08
Android實(shí)現(xiàn)儀表盤(pán)效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)儀表盤(pán)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05
詳解android使用ItemDecoration 懸浮導(dǎo)航欄效果
本篇文章主要介紹了Android 最流行的吸頂效果的實(shí)現(xiàn)及代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。2017-01-01
Android簡(jiǎn)單實(shí)現(xiàn)引導(dǎo)頁(yè)
這篇文章主要為大家詳細(xì)介紹了Android簡(jiǎn)單實(shí)現(xiàn)引導(dǎo)頁(yè),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-04-04
Android手機(jī)衛(wèi)士之綁定sim卡序列號(hào)
這篇文章主要介紹了Android手機(jī)衛(wèi)士之綁定sim卡序列號(hào)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
Android編程實(shí)現(xiàn)WebView自適應(yīng)全屏方法小結(jié)
這篇文章主要介紹了Android編程實(shí)現(xiàn)WebView自適應(yīng)全屏方法,結(jié)合實(shí)例形式總結(jié)了三種常用的WebView自適應(yīng)全屏實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-12-12
Android中okhttp3.4.1+retrofit2.1.0實(shí)現(xiàn)離線緩存
這篇文章主要介紹了Android中okhttp3.4.1結(jié)合retrofit2.1.0實(shí)現(xiàn)離線緩存,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10

