Skip to content

Instantly share code, notes, and snippets.

@T-Spoon
Created January 9, 2015 11:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save T-Spoon/fe9f0ee8cbb79049b1ec to your computer and use it in GitHub Desktop.
Save T-Spoon/fe9f0ee8cbb79049b1ec to your computer and use it in GitHub Desktop.
SwitchCompat - Fix For TextSize Attribute on New SwitchCompat Widget
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