11package com .hjq .toast .demo ;
22
33import android .os .Bundle ;
4+ import android .os .Handler ;
45import android .support .v4 .app .NotificationManagerCompat ;
56import android .support .v7 .app .AppCompatActivity ;
67import android .view .Gravity ;
1112import com .hjq .toast .style .ToastBlackStyle ;
1213import com .hjq .toast .style .ToastQQStyle ;
1314import com .hjq .toast .style .ToastWhiteStyle ;
15+ import com .hjq .xtoast .XToast ;
1416
1517/**
1618 * author : Android 轮子哥
@@ -69,21 +71,36 @@ public void show7(View v) {
6971 ToastUtils .show ("我是自定义Toast" );
7072 }
7173
74+ public void show8 (View v ) {
75+ new XToast (ToastActivity .this )
76+ .setDuration (1000 )
77+ .setView (ToastUtils .getToast ().getView ())
78+ .setAnimStyle (android .R .style .Animation_Translucent )
79+ .setText (android .R .id .message , "就问你溜不溜" )
80+ .show ();
81+ }
82+
7283 @ Override
7384 protected void onRestart () {
7485 super .onRestart ();
86+ // 请注意这段代码强烈建议不要放到实际开发中,因为用户屏蔽通知栏和开启应用状态下的情况极少,可以忽略不计
87+
7588 // 如果通知栏的权限被手动关闭了
7689 if (!NotificationManagerCompat .from (this ).areNotificationsEnabled () &&
7790 !"SupportToast" .equals (ToastUtils .getToast ().getClass ().getSimpleName ())) {
78- // 因为吐司只有初始化的时候才会判断通知权限有没有开启,根据这个通知开关来显示原生的吐司还是兼容的吐司
79- ToastUtils .init (getApplication ());
80- recreate ();
81- getWindow ().getDecorView ().postDelayed (new Runnable () {
82- @ Override
83- public void run () {
84- ToastUtils .show ("检查到你手动关闭了通知权限,正在重新初始化ToastUtils框架" );
85- }
86- }, 1000 );
91+ try {
92+ // 因为吐司只有初始化的时候才会判断通知权限有没有开启,根据这个通知开关来显示原生的吐司还是兼容的吐司
93+ ToastUtils .init (getApplication ());
94+ recreate ();
95+ new Handler ().postDelayed (new Runnable () {
96+ @ Override
97+ public void run () {
98+ try {
99+ ToastUtils .show ("检查到你手动关闭了通知权限,正在重新初始化ToastUtils框架" );
100+ } catch (Exception ignored ) {}
101+ }
102+ }, 2000 );
103+ }catch (Exception ignored ) {}
87104 }
88105 }
89106}
0 commit comments