public ToggleButton(android.content.Context context, android.util.AttributeSet attrs , int defStyle) : base(context, attrs, defStyle) { android.content.res.TypedArray a = context.obtainStyledAttributes(attrs, [email protected] .styleable.ToggleButton, defStyle, 0); mTextOn = a.getText([email protected]_textOn); mTextOff = a.getText([email protected]_textOff); mDisabledAlpha = a.getFloat([email protected]_disabledAlpha , 0.5f); syncTextState(); a.recycle(); }
/// <summary> /// Construct a new Switch with a default style determined by the given theme attribute, /// overriding specific style attributes as requested. /// </summary> /// <remarks> /// Construct a new Switch with a default style determined by the given theme attribute, /// overriding specific style attributes as requested. /// </remarks> /// <param name="context">The Context that will determine this widget's theming.</param> /// <param name="attrs">Specification of attributes that should deviate from the default styling. /// </param> /// <param name="defStyle"> /// An attribute ID within the active theme containing a reference to the /// default style for this widget. e.g. android.R.attr.switchStyle. /// </param> public Switch(android.content.Context context, android.util.AttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { // Enum for the "typeface" XML parameter. // Does not include padding mTextPaint = new android.text.TextPaint(android.graphics.Paint.ANTI_ALIAS_FLAG); android.content.res.Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; mTextPaint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale); android.content.res.TypedArray a = context.obtainStyledAttributes(attrs, [email protected] .styleable.Switch, defStyle, 0); mThumbDrawable = a.getDrawable([email protected]_thumb); mTrackDrawable = a.getDrawable([email protected]_track); mTextOn = a.getText([email protected]_textOn); mTextOff = a.getText([email protected]_textOff); mThumbTextPadding = a.getDimensionPixelSize([email protected]_thumbTextPadding , 0); mSwitchMinWidth = a.getDimensionPixelSize([email protected]_switchMinWidth , 0); mSwitchPadding = a.getDimensionPixelSize([email protected]_switchPadding , 0); int appearance = a.getResourceId([email protected]_switchTextAppearance , 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } a.recycle(); android.view.ViewConfiguration config = android.view.ViewConfiguration.get(context ); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }