154154 * @attr ref android.R.styleable#TextView_textColorLink
155155 * @attr ref android.R.styleable#TextView_textSize
156156 * @attr ref android.R.styleable#TextView_textScaleX
157+ * @attr ref android.R.styleable#TextView_fontFamily
157158 * @attr ref android.R.styleable#TextView_typeface
158159 * @attr ref android.R.styleable#TextView_textStyle
159160 * @attr ref android.R.styleable#TextView_cursorVisible
@@ -464,6 +465,7 @@ public TextView(Context context, AttributeSet attrs, int defStyle) {
464465 ColorStateList textColorHint = null ;
465466 ColorStateList textColorLink = null ;
466467 int textSize = 15 ;
468+ String fontFamily = null ;
467469 int typefaceIndex = -1 ;
468470 int styleIndex = -1 ;
469471 boolean allCaps = false ;
@@ -516,6 +518,10 @@ public TextView(Context context, AttributeSet attrs, int defStyle) {
516518 typefaceIndex = appearance .getInt (attr , -1 );
517519 break ;
518520
521+ case com .android .internal .R .styleable .TextAppearance_fontFamily :
522+ fontFamily = appearance .getString (attr );
523+ break ;
524+
519525 case com .android .internal .R .styleable .TextAppearance_textStyle :
520526 styleIndex = appearance .getInt (attr , -1 );
521527 break ;
@@ -781,6 +787,10 @@ public TextView(Context context, AttributeSet attrs, int defStyle) {
781787 styleIndex = a .getInt (attr , styleIndex );
782788 break ;
783789
790+ case com .android .internal .R .styleable .TextView_fontFamily :
791+ fontFamily = a .getString (attr );
792+ break ;
793+
784794 case com .android .internal .R .styleable .TextView_password :
785795 password = a .getBoolean (attr , password );
786796 break ;
@@ -1051,7 +1061,7 @@ public TextView(Context context, AttributeSet attrs, int defStyle) {
10511061 typefaceIndex = MONOSPACE ;
10521062 }
10531063
1054- setTypefaceByIndex ( typefaceIndex , styleIndex );
1064+ setTypefaceFromAttrs ( fontFamily , typefaceIndex , styleIndex );
10551065
10561066 if (shadowcolor != 0 ) {
10571067 setShadowLayer (r , dx , dy , shadowcolor );
@@ -1111,8 +1121,15 @@ public TextView(Context context, AttributeSet attrs, int defStyle) {
11111121 }
11121122 }
11131123
1114- private void setTypefaceByIndex ( int typefaceIndex , int styleIndex ) {
1124+ private void setTypefaceFromAttrs ( String familyName , int typefaceIndex , int styleIndex ) {
11151125 Typeface tf = null ;
1126+ if (familyName != null ) {
1127+ tf = Typeface .create (familyName , styleIndex );
1128+ if (tf != null ) {
1129+ setTypeface (tf );
1130+ return ;
1131+ }
1132+ }
11161133 switch (typefaceIndex ) {
11171134 case SANS :
11181135 tf = Typeface .SANS_SERIF ;
@@ -2160,14 +2177,17 @@ public void setTextAppearance(Context context, int resid) {
21602177 setLinkTextColor (colors );
21612178 }
21622179
2180+ String familyName ;
21632181 int typefaceIndex , styleIndex ;
21642182
2183+ familyName = appearance .getString (com .android .internal .R .styleable .
2184+ TextAppearance_fontFamily );
21652185 typefaceIndex = appearance .getInt (com .android .internal .R .styleable .
21662186 TextAppearance_typeface , -1 );
21672187 styleIndex = appearance .getInt (com .android .internal .R .styleable .
21682188 TextAppearance_textStyle , -1 );
21692189
2170- setTypefaceByIndex ( typefaceIndex , styleIndex );
2190+ setTypefaceFromAttrs ( familyName , typefaceIndex , styleIndex );
21712191
21722192 if (appearance .getBoolean (com .android .internal .R .styleable .TextAppearance_textAllCaps ,
21732193 false )) {
@@ -2269,6 +2289,7 @@ public void setTextScaleX(float size) {
22692289 *
22702290 * @see #getTypeface()
22712291 *
2292+ * @attr ref android.R.styleable#TextView_fontFamily
22722293 * @attr ref android.R.styleable#TextView_typeface
22732294 * @attr ref android.R.styleable#TextView_textStyle
22742295 */
@@ -2290,6 +2311,7 @@ public void setTypeface(Typeface tf) {
22902311 *
22912312 * @see #setTypeface(Typeface)
22922313 *
2314+ * @attr ref android.R.styleable#TextView_fontFamily
22932315 * @attr ref android.R.styleable#TextView_typeface
22942316 * @attr ref android.R.styleable#TextView_textStyle
22952317 */
@@ -3690,15 +3712,15 @@ public void setInputType(int type) {
36903712 boolean forceUpdate = false ;
36913713 if (isPassword ) {
36923714 setTransformationMethod (PasswordTransformationMethod .getInstance ());
3693- setTypefaceByIndex ( MONOSPACE , 0 );
3715+ setTypefaceFromAttrs ( null /* fontFamily */ , MONOSPACE , 0 );
36943716 } else if (isVisiblePassword ) {
36953717 if (mTransformation == PasswordTransformationMethod .getInstance ()) {
36963718 forceUpdate = true ;
36973719 }
3698- setTypefaceByIndex ( MONOSPACE , 0 );
3720+ setTypefaceFromAttrs ( null /* fontFamily */ , MONOSPACE , 0 );
36993721 } else if (wasPassword || wasVisiblePassword ) {
37003722 // not in password mode, clean up typeface and transformation
3701- setTypefaceByIndex ( -1 , -1 );
3723+ setTypefaceFromAttrs ( null /* fontFamily */ , -1 , -1 );
37023724 if (mTransformation == PasswordTransformationMethod .getInstance ()) {
37033725 forceUpdate = true ;
37043726 }
0 commit comments