4
4
import android .content .ClipData ;
5
5
import android .content .ClipboardManager ;
6
6
import android .content .Context ;
7
- import android .support .design .widget .Snackbar ;
7
+ import android .graphics .Color ;
8
+ import android .text .SpannableStringBuilder ;
9
+ import android .text .Spanned ;
10
+ import android .text .style .ForegroundColorSpan ;
8
11
import android .view .Menu ;
9
12
import android .view .View ;
10
13
import android .view .inputmethod .InputMethodManager ;
11
- import android .widget .TextView ;
12
14
15
+ import com .google .android .material .snackbar .Snackbar ;
13
16
import com .joanzapata .iconify .Icon ;
14
17
import com .joanzapata .iconify .IconDrawable ;
15
18
@@ -24,28 +27,30 @@ public class Utils {
24
27
25
28
public static void showSnackbar (View parent , String content ) {
26
29
Context context = parent .getContext ();
27
- Snackbar snackbar = Snackbar .make (parent , content , Snackbar .LENGTH_LONG );
30
+ SpannableStringBuilder spannableString = new SpannableStringBuilder (content );
31
+ spannableString .setSpan (
32
+ new ForegroundColorSpan (Color .WHITE ),
33
+ 0 ,
34
+ content .length (),
35
+ Spanned .SPAN_EXCLUSIVE_EXCLUSIVE );
36
+ Snackbar snackbar = Snackbar .make (parent , spannableString , Snackbar .LENGTH_LONG );
28
37
View view = snackbar .getView ();
29
38
view .setBackgroundColor (context .getResources ().getColor (R .color .app_turquoise ));
30
- TextView textView = view .findViewById (android .support .design .R .id .snackbar_text );
31
- textView .setTextColor (context .getResources ().getColor (R .color .white ));
32
39
snackbar .show ();
33
40
}
34
41
35
42
public static void showLongSnackbar (View parent , String content ) {
36
43
Context context = parent .getContext ();
44
+ SpannableStringBuilder spannableString = new SpannableStringBuilder (content );
45
+ spannableString .setSpan (
46
+ new ForegroundColorSpan (Color .WHITE ),
47
+ 0 ,
48
+ content .length (),
49
+ Spanned .SPAN_EXCLUSIVE_EXCLUSIVE );
37
50
final Snackbar snackbar = Snackbar .make (parent , content , Snackbar .LENGTH_INDEFINITE );
38
51
View view = snackbar .getView ();
39
52
view .setBackgroundColor (context .getResources ().getColor (R .color .app_turquoise ));
40
- TextView textView = view .findViewById (android .support .design .R .id .snackbar_text );
41
- textView .setTextColor (context .getResources ().getColor (R .color .white ));
42
- textView .setMaxLines (8 );
43
- snackbar .setAction (R .string .dismiss , new View .OnClickListener () {
44
- @ Override
45
- public void onClick (View v ) {
46
- snackbar .dismiss ();
47
- }
48
- });
53
+ snackbar .setAction (R .string .dismiss , v -> snackbar .dismiss ());
49
54
snackbar .setActionTextColor (context .getResources ().getColor (R .color .white ));
50
55
snackbar .show ();
51
56
}
0 commit comments