99import android .graphics .Rect ;
1010import android .graphics .RectF ;
1111import android .graphics .Shader ;
12+ import android .graphics .Typeface ;
1213import android .support .v4 .content .ContextCompat ;
1314import android .text .TextPaint ;
1415import android .util .AttributeSet ;
@@ -55,6 +56,8 @@ public class MarqueeTextView extends View {
5556 int topOffset ;
5657 int xOffset ;
5758
59+ Typeface customTypeface ;
60+
5861 public static void setGlobalDefaultPauseDuration (int pauseDuration ) {
5962 DEFAULT_PAUSE_DURATION = pauseDuration ;
6063 }
@@ -133,7 +136,7 @@ protected void onDraw(Canvas canvas) {
133136
134137 float leftMargin = 0 ;
135138
136- if (centerText ){
139+ if (centerText ) {
137140 leftMargin = (viewWidth - textWidth ) / 2 ;
138141 }
139142
@@ -244,6 +247,10 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
244247 paint .density = getResources ().getDisplayMetrics ().density ;
245248 paint .setTextSize (textSize );
246249
250+ if (customTypeface != null ) {
251+ paint .setTypeface (customTypeface );
252+ }
253+
247254 height = (int ) (Math .abs (paint .ascent ()) + Math .abs (paint .descent ()));
248255 }
249256
@@ -258,6 +265,10 @@ void renewPaint() {
258265 textPaint .setTextSize (textSize );
259266 textPaint .setColor (textColor );
260267
268+ if (customTypeface != null ) {
269+ textPaint .setTypeface (customTypeface );
270+ }
271+
261272 int absEdgeEffectWidth = (getMeasuredWidth () / 100 ) * edgeEffectWidth ;
262273
263274 Shader leftShader = new LinearGradient (
@@ -312,7 +323,7 @@ public void setText(CharSequence text) {
312323 public CharSequence getText () {
313324 return text ;
314325 }
315-
326+
316327 public void setTextColor (int color ) {
317328 textColor = color ;
318329 renewPaint ();
@@ -351,4 +362,8 @@ public void setEdgeEffectEnabled(boolean edgeEffectEnabled) {
351362 invalidate ();
352363 }
353364
365+ public void setCustomTypeface (Typeface customTypeface ) {
366+ this .customTypeface = customTypeface ;
367+ }
368+
354369}
0 commit comments