1
1
package com .blankj .utilcode .utils ;
2
2
3
3
import android .support .annotation .ColorInt ;
4
+ import android .support .design .widget .BaseTransientBottomBar ;
4
5
import android .support .design .widget .Snackbar ;
5
6
import android .view .Gravity ;
6
7
import android .view .LayoutInflater ;
@@ -92,8 +93,8 @@ public static void showLongSnackbar(View parent, CharSequence text, @ColorInt in
92
93
* @param textColor 文本颜色
93
94
* @param bgColor 背景色
94
95
*/
95
- public static void showIndefiniteSnackbar (View parent , CharSequence text , int duration , @ ColorInt int textColor , @ ColorInt int bgColor ) {
96
- showSnackbar (parent , text , duration , textColor , bgColor , null , -1 , null );
96
+ public static void showIndefiniteSnackbar (View parent , CharSequence text , @ ColorInt int textColor , @ ColorInt int bgColor ) {
97
+ showSnackbar (parent , text , Snackbar . LENGTH_INDEFINITE , textColor , bgColor , null , -1 , null );
97
98
}
98
99
99
100
/**
@@ -108,9 +109,9 @@ public static void showIndefiniteSnackbar(View parent, CharSequence text, int du
108
109
* @param actionTextColor 事件文本颜色
109
110
* @param listener 监听器
110
111
*/
111
- public static void showIndefiniteSnackbar (View parent , CharSequence text , int duration , @ ColorInt int textColor , @ ColorInt int bgColor ,
112
+ public static void showIndefiniteSnackbar (View parent , CharSequence text , @ ColorInt int textColor , @ ColorInt int bgColor ,
112
113
CharSequence actionText , int actionTextColor , View .OnClickListener listener ) {
113
- showSnackbar (parent , text , duration , textColor , bgColor ,
114
+ showSnackbar (parent , text , Snackbar . LENGTH_INDEFINITE , textColor , bgColor ,
114
115
actionText , actionTextColor , listener );
115
116
}
116
117
@@ -126,26 +127,21 @@ public static void showIndefiniteSnackbar(View parent, CharSequence text, int du
126
127
* @param actionTextColor 事件文本颜色
127
128
* @param listener 监听器
128
129
*/
129
- private static void showSnackbar (View parent , CharSequence text , int duration , @ ColorInt int textColor , @ ColorInt int bgColor ,
130
- CharSequence actionText , int actionTextColor , View .OnClickListener listener ) {
131
- switch (duration ) {
132
- default :
133
- case Snackbar .LENGTH_SHORT :
134
- case Snackbar .LENGTH_LONG :
135
- snackbarWeakReference = new WeakReference <>(Snackbar .make (parent , text , duration ));
136
- break ;
137
- case Snackbar .LENGTH_INDEFINITE :
138
- snackbarWeakReference = new WeakReference <>(Snackbar .make (parent , text , Snackbar .LENGTH_INDEFINITE ).setDuration (duration ));
139
- }
130
+ private static void showSnackbar (View parent , CharSequence text ,
131
+ @ BaseTransientBottomBar .Duration int duration ,
132
+ @ ColorInt int textColor , @ ColorInt int bgColor ,
133
+ CharSequence actionText , int actionTextColor ,
134
+ View .OnClickListener listener ) {
135
+ snackbarWeakReference = new WeakReference <>(Snackbar .make (parent , text , duration ));
140
136
Snackbar snackbar = snackbarWeakReference .get ();
141
137
View view = snackbar .getView ();
142
138
snackbar .setActionTextColor (textColor );
143
139
view .setBackgroundColor (bgColor );
144
140
if (actionText != null && actionText .length () > 0 && listener != null ) {
145
- snackbarWeakReference . get () .setActionTextColor (actionTextColor );
146
- snackbarWeakReference . get () .setAction (actionText , listener );
141
+ snackbar .setActionTextColor (actionTextColor );
142
+ snackbar .setAction (actionText , listener );
147
143
}
148
- snackbarWeakReference . get () .show ();
144
+ snackbar .show ();
149
145
}
150
146
151
147
/**
0 commit comments