1 public class FontSizeSwitchPreferenceCompat extends SwitchPreferenceCompat { 2 3 private Context mContext = null; 4 5 public FontSizeSwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyle) { 6 super(context, attrs, defStyle); 7 mContext = context; 8 } 9 10 public FontSizeSwitchPreferenceCompat(Context context, AttributeSet attrs) { 11 super(context, attrs); 12 mContext = context; 13 } 14 15 public FontSizeSwitchPreferenceCompat(Context context) { 16 super(context); 17 mContext = context; 18 } 19 20 @Override 21 protected View onCreateView(ViewGroup parent) { 22 View view = super.onCreateView(parent); 23 24 try { 25 // 行高 26 view.getLayoutParams().height = ScreenUtils.dpToPx(mContext, 44); 27 28 LinearLayout linearLayout = (LinearLayout) view; 29 linearLayout.setPadding(0, 0, 0, 0); 30 31 ViewGroup viewGroup = (ViewGroup) view; 32 ViewGroup childViewGroup = (ViewGroup) viewGroup.getChildAt(1); 33 34 TextView titleView = (TextView) childViewGroup.getChildAt(0); 35 titleView.setTextSize(17); 36 titleView.setTextColor(Color.BLACK); 37 } catch (Exception e){ 38 e.printStackTrace(); 39 } 40 41 return view; 42 43 } 44 }