Created
January 9, 2015 11:38
-
-
Save T-Spoon/fe9f0ee8cbb79049b1ec to your computer and use it in GitHub Desktop.
SwitchCompat - Fix For TextSize Attribute on New SwitchCompat Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SwitchCompatFix extends SwitchCompat { | |
public SwitchCompatFix(Context context) { | |
super(context); | |
} | |
public SwitchCompatFix(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public SwitchCompatFix(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
@Override | |
public void setSwitchTextAppearance(Context context, int resid) { | |
TypedArray appearance = context.obtainStyledAttributes(resid, new int[]{android.R.attr.textSize}); | |
int ts = appearance.getDimensionPixelSize(0, 0); | |
try { | |
Field field = SwitchCompat.class.getDeclaredField("mTextPaint"); | |
field.setAccessible(true); | |
TextPaint textPaint = (TextPaint) field.get(this); | |
textPaint.setTextSize(ts); | |
} catch (NoSuchFieldException e) { | |
e.printStackTrace(); | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
appearance.recycle(); | |
super.setSwitchTextAppearance(context, resid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment