private void Initialize(IAttributeSet attrs) { //Load those if set in xml resource file. TypedArray a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.ColorPickerView); mShowAlphaPanel = a.GetBoolean(Resource.Styleable.ColorPickerView_alphaChannelVisible, false); mAlphaSliderText = a.GetString(Resource.Styleable.ColorPickerView_alphaChannelText); //TODO : cross check calculation mSliderTrackerColor = a.GetColor(Resource.Styleable.ColorPickerView_colorPickerSliderColor, Int32.Parse("FFBDBDBD", System.Globalization.NumberStyles.HexNumber)); mBorderColor = a.GetColor(Resource.Styleable.ColorPickerView_colorPickerBorderColor, Int32.Parse("FF6E6E6E", System.Globalization.NumberStyles.HexNumber)); a.Recycle(); mDensity = Context.Resources.DisplayMetrics.Density; PALETTE_CIRCLE_TRACKER_RADIUS *= mDensity; RECTANGLE_TRACKER_OFFSET *= mDensity; HUE_PANEL_WIDTH *= mDensity; ALPHA_PANEL_HEIGHT *= mDensity; PANEL_SPACING = PANEL_SPACING * mDensity; mDrawingOffset = calculateRequiredOffset(); initPaintTools(); //Needed for receiving trackball motion events. Focusable = true; FocusableInTouchMode = true; }
private void Init(Android.Content.Context context, IAttributeSet attrs, int p) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleProgressBar, p, 0); float density = context.Resources.DisplayMetrics.Density; mBackGroundColor = a.GetColor(Resource.Styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT); mProgressColor = a.GetColor(Resource.Styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT); mInnerRadius = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_inner_radius, -1); mProgressStokeWidth = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_progress_stoke_width, (int)(STROKE_WIDTH_LARGE * density)); mArrowWidth = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_arrow_width, -1); mArrowHeight = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_arrow_height, -1); mTextSize = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_progress_text_size, (int)(DEFAULT_TEXT_SIZE * density)); mTextColor = a.GetColor(Resource.Styleable.CircleProgressBar_mlpb_progress_text_color, Color.Black); mShowArrow = a.GetBoolean(Resource.Styleable.CircleProgressBar_mlpb_show_arrow, false); mCircleBackgroundEnabled = a.GetBoolean(Resource.Styleable.CircleProgressBar_mlpb_enable_circle_background, true); mProgress = a.GetInt(Resource.Styleable.CircleProgressBar_mlpb_progress, 0); mMax = a.GetInt(Resource.Styleable.CircleProgressBar_mlpb_max, 100); int textVisible = a.GetInt(Resource.Styleable.CircleProgressBar_mlpb_progress_text_visibility, 1); if (textVisible != 1) { mIfDrawText = true; } mTextPaint = new Paint(); mTextPaint.SetStyle(Paint.Style.Fill); mTextPaint.Color = mTextColor; mTextPaint.TextSize = mTextSize; mTextPaint.AntiAlias = true; a.Recycle(); mProgressDrawable = new MaterialProgressDrawale(Context, this); base.SetImageDrawable(mProgressDrawable); }
/** * Instantiates a new holo circular progress bar. * * @param context the context * @param attrs the attrs * @param defStyle the def style */ public HoloCircularProgressBar(Context context, IAttributeSet Attrs, int DefStyle) : base(context, Attrs, DefStyle) { // load the styled attributes and set their properties TypedArray attributes = context.ObtainStyledAttributes(Attrs, Resource.Styleable.HoloCircularProgressBar, DefStyle, 0); if (attributes != null) { try { SetProgressColor(attributes.GetColor(Resource.Styleable.HoloCircularProgressBar_progress_color, Color.Cyan)); SetProgressBackgroundColor(attributes.GetColor(Resource.Styleable.HoloCircularProgressBar_progress_background_color, Color.Green)); SetProgress(attributes.GetFloat(Resource.Styleable.HoloCircularProgressBar_progress, 0.0f)); SetMarkerProgress(attributes.GetFloat(Resource.Styleable.HoloCircularProgressBar_marker_progress, 0.0f)); SetWheelSize((int)attributes.GetDimension(Resource.Styleable.HoloCircularProgressBar_stroke_width, 10)); SetThumbEnabled(attributes.GetBoolean(Resource.Styleable.HoloCircularProgressBar_thumb_visible, true)); SetMarkerEnabled(attributes.GetBoolean(Resource.Styleable.HoloCircularProgressBar_marker_visible, true)); _gravity = (GravityFlags)attributes.GetInt(Resource.Styleable.HoloCircularProgressBar_android_gravity, (int)GravityFlags.Center); } finally { // make sure recycle is always called. attributes.Recycle(); } } _thumbRadius = _circleStrokeWidth * 2; UpdateBackgroundColor(); UpdateMarkerColor(); UpdateProgressColor(); // the view has now all properties and can be drawn _isInitializing = false; }
private void Init(Context context, IAttributeSet attrs) { anim = new CircleBarAnim(this); defaultSize = DpOrPxUtils.dip2px(context, 100); barWidth = DpOrPxUtils.dip2px(context, 10); TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleBarView); progressColor = typedArray.GetColor(Resource.Styleable.CircleBarView_progress_color, Color.Green); //默认为绿色 bgColor = typedArray.GetColor(Resource.Styleable.CircleBarView_bg_color, Color.Gray); //默认为灰色 startAngle = typedArray.GetFloat(Resource.Styleable.CircleBarView_start_angle, 0); //默认为0 sweepAngle = typedArray.GetFloat(Resource.Styleable.CircleBarView_sweep_angle, 360); //默认为360 barWidth = typedArray.GetDimension(Resource.Styleable.CircleBarView_bar_width, DpOrPxUtils.dip2px(context, 10)); //默认为10dp typedArray.Recycle(); //typedArray用完之后需要回收,防止内存泄漏 progressPaint = new Paint(); progressPaint.StrokeCap = Paint.Cap.Round; progressPaint.SetStyle(Paint.Style.Stroke); //只描边,不填充 progressPaint.Color = progressColor; progressPaint.AntiAlias = true; //设置抗锯齿 progressPaint.StrokeWidth = barWidth; //随便设置一个画笔宽度,看看效果就好,之后会通过attr自定义属性进行设置 bgPaint = new Paint(); bgPaint.StrokeCap = Paint.Cap.Round; bgPaint.SetStyle(Paint.Style.Stroke); //只描边,不填充 bgPaint.Color = bgColor; bgPaint.AntiAlias = true; //设置抗锯齿 bgPaint.StrokeWidth = barWidth; NowProgressNum = 0; progressNum = 0; maxNum = 100;//也是随便设的 }
private void initButton(Context context, IAttributeSet attrs) { if (context is Activity) { init((Activity)context); } TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.ShineButton); btnColor = a.GetColor(Resource.Styleable.ShineButton_btn_color, Color.Gray); btnFillColor = a.GetColor(Resource.Styleable.ShineButton_btn_fill_color, Color.Black); shineParams.allowRandomColor = a.GetBoolean(Resource.Styleable.ShineButton_allow_random_color, false); shineParams.animDuration = a.GetInteger(Resource.Styleable.ShineButton_shine_animation_duration, (int)shineParams.animDuration); shineParams.bigShineColor = a.GetColor(Resource.Styleable.ShineButton_big_shine_color, shineParams.bigShineColor); shineParams.clickAnimDuration = a.GetInteger(Resource.Styleable.ShineButton_click_animation_duration, (int)shineParams.clickAnimDuration); shineParams.enableFlashing = a.GetBoolean(Resource.Styleable.ShineButton_enable_flashing, false); shineParams.shineCount = a.GetInteger(Resource.Styleable.ShineButton_shine_count, shineParams.shineCount); shineParams.shineDistanceMultiple = a.GetFloat(Resource.Styleable.ShineButton_shine_distance_multiple, shineParams.shineDistanceMultiple); shineParams.shineTurnAngle = a.GetFloat(Resource.Styleable.ShineButton_shine_turn_angle, shineParams.shineTurnAngle); shineParams.smallShineColor = a.GetColor(Resource.Styleable.ShineButton_small_shine_color, shineParams.smallShineColor); shineParams.smallShineOffsetAngle = a.GetFloat(Resource.Styleable.ShineButton_small_shine_offset_angle, shineParams.smallShineOffsetAngle); shineParams.shineSize = a.GetDimensionPixelSize(Resource.Styleable.ShineButton_shine_size, shineParams.shineSize); a.Recycle(); setSrcColor(btnColor); }
public void InitButton(Context context, IAttributeSet attrs) { Activity activityCaller = context as Activity; if (activityCaller != null) { Init((Activity)context); } TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.ShineButton); btnColor = a.GetColor(Resource.Styleable.ShineButton_btn_color, Color.Gray); ButtonFillColour = a.GetColor(Resource.Styleable.ShineButton_btn_fill_color, Color.Black); shineParams.UseRandomColor = a.GetBoolean(Resource.Styleable.ShineButton_allow_random_color, false); shineParams.AnimDuration = a.GetInteger(Resource.Styleable.ShineButton_shine_animation_duration, (int)shineParams.AnimDuration); shineParams.BigShineColor = a.GetColor(Resource.Styleable.ShineButton_big_shine_color, shineParams.BigShineColor); shineParams.ClickAnimDuration = a.GetInteger(Resource.Styleable.ShineButton_click_animation_duration, (int)shineParams.ClickAnimDuration); shineParams.EnableFlashing = a.GetBoolean(Resource.Styleable.ShineButton_enable_flashing, false); shineParams.ShineCount = a.GetInteger(Resource.Styleable.ShineButton_shine_count, shineParams.ShineCount); shineParams.ShineDistanceMultiple = a.GetFloat(Resource.Styleable.ShineButton_shine_distance_multiple, shineParams.ShineDistanceMultiple); shineParams.ShineTurnAngle = a.GetFloat(Resource.Styleable.ShineButton_shine_turn_angle, shineParams.ShineTurnAngle); shineParams.SmallShineColor = a.GetColor(Resource.Styleable.ShineButton_small_shine_color, shineParams.SmallShineColor); shineParams.SmallShineOffsetAngle = a.GetFloat(Resource.Styleable.ShineButton_small_shine_offset_angle, shineParams.SmallShineOffsetAngle); shineParams.ShineSize = a.GetDimensionPixelSize(Resource.Styleable.ShineButton_shine_size, shineParams.ShineSize); a.Recycle(); SourceColour = btnColor; }
private void initAttributes(Context context, IAttributeSet attributeSet) { TypedArray attr = getTypedArray(context, attributeSet, Resource.Styleable.ProcessButton); if (attr == null) { return; } try { mLoadingText = attr.GetString(Resource.Styleable.ProcessButton_pb_textProgress); mCompleteText = attr.GetString(Resource.Styleable.ProcessButton_pb_textComplete); mErrorText = attr.GetString(Resource.Styleable.ProcessButton_pb_textError); int purple = getColor(Resource.Color.purple_progress); int colorProgress = attr.GetColor(Resource.Styleable.ProcessButton_pb_colorProgress, purple); mProgressDrawable.SetColor(colorProgress); int green = getColor(Resource.Color.green_complete); int colorComplete = attr.GetColor(Resource.Styleable.ProcessButton_pb_colorComplete, green); mCompleteDrawable.SetColor(colorComplete); int red = getColor(Resource.Color.red_error); int colorError = attr.GetColor(Resource.Styleable.ProcessButton_pb_colorError, red); mErrorDrawable.SetColor(colorError); } finally { attr.Recycle(); } }
public void ApplyStylableAttributes(Context context, TypedArray a, int[] styleableRes) { if (styleableRes == Resource.Styleable.RightAngleTriangle) { if (a.HasValue(Resource.Styleable.RightAngleTriangle_rightAnglePosition)) { RightAnglePosition = (RightAnglePosition)a.GetInt(Resource.Styleable.RightAngleTriangle_rightAnglePosition, 0); } if (a.HasValue(Resource.Styleable.RightAngleTriangle_fillColor)) { FillColor = a.GetColor(Resource.Styleable.RightAngleTriangle_fillColor, Color.White); } if (a.HasValue(Resource.Styleable.RightAngleTriangle_borderWidth)) { var borderWidth = a.GetDimensionPixelSize(Resource.Styleable.RightAngleTriangle_borderWidth, 0); BorderThicknessPx = borderWidth > 0 ? borderWidth : 0; } if (a.HasValue(Resource.Styleable.RightAngleTriangle_borderColor)) { BorderColor = a.GetColor(Resource.Styleable.RightAngleTriangle_borderColor, Color.Transparent); } } }
private LayerDrawable createNormalDrawable(TypedArray attr) { LayerDrawable drawableNormal = (LayerDrawable)getDrawable(Resource.Drawable.rect_normal).Mutate(); GradientDrawable drawableTop = (GradientDrawable)drawableNormal.GetDrawable(0).Mutate(); drawableTop.SetCornerRadius(getCornerRadius()); int blueDark = getColor(Resource.Color.blue_pressed); int colorPressed = attr.GetColor(Resource.Styleable.FlatButton_pb_colorPressed, blueDark); drawableTop.SetColor(colorPressed); GradientDrawable drawableBottom = (GradientDrawable)drawableNormal.GetDrawable(1).Mutate(); drawableBottom.SetCornerRadius(getCornerRadius()); int blueNormal = getColor(Resource.Color.blue_normal); int colorNormal = attr.GetColor(Resource.Styleable.FlatButton_pb_colorNormal, blueNormal); drawableBottom.SetColor(colorNormal); return(drawableNormal); }
private void init(IAttributeSet attrs) { TypedArray a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.ColorPickerPreference); showDialogTitle = a.GetBoolean(Resource.Styleable.ColorPickerPreference_showDialogTitle, false); showPreviewSelectedColorInList = a.GetBoolean(Resource.Styleable.ColorPickerPreference_showSelectedColorInList, true); a.Recycle(); a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.ColorPickerView); alphaChannelVisible = a.GetBoolean(Resource.Styleable.ColorPickerView_alphaChannelVisible, false); alphaChannelText = a.GetString(Resource.Styleable.ColorPickerView_alphaChannelText); colorPickerSliderColor = a.GetColor(Resource.Styleable.ColorPickerView_colorPickerSliderColor, -1); colorPickerBorderColor = a.GetColor(Resource.Styleable.ColorPickerView_colorPickerBorderColor, -1); a.Recycle(); if (showPreviewSelectedColorInList) { WidgetLayoutResource = Resource.Layout.preference_preview_layout; } if (!showDialogTitle) { DialogTitle = null; } DialogLayoutResource = Resource.Layout.dialog_color_picker; SetPositiveButtonText(Resource.String.dialog_ok); SetNegativeButtonText(Resource.String.dialog_cancle); Persistent = true; }
public AnimatedPathView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { mStrokePaint.SetStyle(Paint.Style.Stroke); mFillPaint.SetStyle(Paint.Style.Fill); TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.AnimatedPathView, defStyle, 0); try { if (a != null) { mStrokePaint.StrokeWidth = a.GetDimensionPixelSize(Resource.Styleable.AnimatedPathView_strokeWidth, 1); mStrokePaint.Color = a.GetColor(Resource.Styleable.AnimatedPathView_strokeColor, unchecked ((int)0xff000000)); svg = new SvgHelper(mStrokePaint); mFillPaint.Color = a.GetColor(Resource.Styleable.AnimatedPathView_fillColor, unchecked ((int)0xff000000)); phase = a.GetFloat(Resource.Styleable.AnimatedPathView_phase, 0.0f); duration = a.GetInt(Resource.Styleable.AnimatedPathView_duration, 4000); fillDuration = a.GetInt(Resource.Styleable.AnimatedPathView_fillDuration, 4000); fillOffset = a.GetInt(Resource.Styleable.AnimatedPathView_fillOffset, 2000); fadeFactor = a.GetFloat(Resource.Styleable.AnimatedPathView_fadeFactor, 10.0f); svgResource = a.GetResourceId(Resource.Styleable.AnimatedPathView_svgPath, 0); } } finally { if (a != null) { a.Recycle(); } } }
private void LoadAttribute(Context context, IAttributeSet attrs) { TypedArray typedArray = context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.MusicBar, 0, 0); try { MLoadedBarSecondaryPaint.Color = typedArray.GetColor( Resource.Styleable.MusicBar_LoadedBarSecondaryColor, ContextCompat.GetColor(context, Resource.Color.LoadedBarSecondaryColor)); MBackgroundBarSecondaryPaint.Color = typedArray.GetColor( Resource.Styleable.MusicBar_backgroundBarSecondaryColor, ContextCompat.GetColor(context, Resource.Color.BackgroundBarSecondaryColor)); IsDivided = typedArray.GetBoolean(Resource.Styleable.MusicBar_divided, false); MDividerSize = typedArray.GetFloat(Resource.Styleable.MusicBar_dividerSize, 2); MBarWidth = typedArray.GetFloat(Resource.Styleable.MusicBar_barWidth, 3); MLoadedBarPrimeColor.StrokeWidth = MBarWidth; MBackgroundBarPrimeColor.StrokeWidth = MBarWidth; MLoadedBarSecondaryPaint.StrokeWidth = MBarWidth; MBackgroundBarSecondaryPaint.StrokeWidth = MBarWidth; MDividerSize = MBarWidth + MDividerSize; } catch (Exception e) { Console.WriteLine(e); } finally { typedArray.Recycle(); } }
/** * Parse the attributes passed to the view from the XML * * @param a the attributes to parse */ private void ParseAttributes(TypedArray a) { DisplayMetrics metrics = Context.Resources.DisplayMetrics;// GetContext().getResources().getDisplayMetrics(); barWidth = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, barWidth, metrics); rimWidth = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, rimWidth, metrics); circleRadius = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, circleRadius, metrics); circleRadius = (int)a.GetDimension(Resource.Styleable.CircleProgressView_matProg_circleRadius, circleRadius); fillRadius = a.GetBoolean(Resource.Styleable.CircleProgressView_matProg_fillRadius, false); barWidth = (int)a.GetDimension(Resource.Styleable.CircleProgressView_matProg_barWidth, barWidth); rimWidth = (int)a.GetDimension(Resource.Styleable.CircleProgressView_matProg_rimWidth, rimWidth); float baseSpinSpeed = a.GetFloat(Resource.Styleable.CircleProgressView_matProg_spinSpeed, spinSpeed / 360.0f); spinSpeed = baseSpinSpeed * 360; barSpinCycleTime = a.GetInt(Resource.Styleable.CircleProgressView_matProg_barSpinCycleTime, (int)barSpinCycleTime); barColor = a.GetColor(Resource.Styleable.CircleProgressView_matProg_barColor, barColor); rimColor = a.GetColor(Resource.Styleable.CircleProgressView_matProg_rimColor, rimColor); linearProgress = a.GetBoolean(Resource.Styleable.CircleProgressView_matProg_linearProgress, false); if (a.GetBoolean(Resource.Styleable.CircleProgressView_matProg_progressIndeterminate, false)) { Spin(); } a.Recycle(); }
/// <summary> /// Initializes a new instance of the <see cref="PagerSlidingTabStrip"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="attrs">The attributes from xml.</param> /// <param name="defStyle">The default style.</param> public PagerSlidingTabStrip(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { HorizontalScrollBarEnabled = false; FillViewport = true; SetWillNotDraw(false); _tabsContainer = new LinearLayout(context); _tabsContainer.Orientation = Android.Widget.Orientation.Horizontal; _tabsContainer.LayoutParameters = new ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); AddView(_tabsContainer); DisplayMetrics dm = Resources.DisplayMetrics; _scrollOffset = Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, _scrollOffset, dm)); _indicatorHeight = Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, _indicatorHeight, dm)); _underlineHeight = Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, _underlineHeight, dm)); _tabDividerPadding = Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, _tabDividerPadding, dm)); _tabPadding = Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, _tabPadding, dm)); _dividerWidth = Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, _dividerWidth, dm)); _tabTextSize = Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, _tabTextSize, dm)); // get system attrs (android:textSize and android:textColor) TypedArray a = context.ObtainStyledAttributes(attrs, ATTRS); _tabTextSize = a.GetDimensionPixelSize(0, _tabTextSize); _tabTextColor = a.GetColor(1, _tabTextColor); a.Recycle(); // get custom attrs a = context.ObtainStyledAttributes(attrs, Resource.Styleable.PagerSlidingTabStrip); _indicatorColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_indicatorColor, _indicatorColor); _underlineColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_underlineColor, _underlineColor); _dividerColor = a.GetColor(Resource.Styleable.PagerSlidingTabStrip_dividerColor, _dividerColor); _indicatorHeight = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_indicatorHeight, _indicatorHeight); _underlineHeight = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_underlineHeight, _underlineHeight); _tabDividerPadding = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_tabDividerPadding, _tabDividerPadding); _tabPadding = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_tabPaddingLeftRight, _tabPadding); _tabBackgroundResId = a.GetResourceId(Resource.Styleable.PagerSlidingTabStrip_tabBackground, _tabBackgroundResId); _shouldExpand = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_shouldExpand, _shouldExpand); _scrollOffset = a.GetDimensionPixelSize(Resource.Styleable.PagerSlidingTabStrip_scrollOffset, _scrollOffset); _tabTextAllCaps = a.GetBoolean(Resource.Styleable.PagerSlidingTabStrip_tabTextAllCaps, _tabTextAllCaps); a.Recycle(); _rectPaint = new Paint(); _rectPaint.AntiAlias = true; _rectPaint.SetStyle(Android.Graphics.Paint.Style.Fill); _dividerPaint = new Paint(); _dividerPaint.AntiAlias = true; _dividerPaint.StrokeWidth = _dividerWidth; _defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent); _expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MatchParent, 1.0f); }
private void ReadAttrs(Context context, IAttributeSet attrs, int defStyle) { TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.GaugeView, defStyle, 0); mShowOuterShadow = typedArray.GetBoolean(Resource.Styleable.GaugeView_showOuterShadow, SHOW_OUTER_SHADOW); mShowOuterBorder = typedArray.GetBoolean(Resource.Styleable.GaugeView_showOuterBorder, SHOW_OUTER_BORDER); mShowOuterRim = typedArray.GetBoolean(Resource.Styleable.GaugeView_showOuterRim, SHOW_OUTER_RIM); mShowInnerRim = typedArray.GetBoolean(Resource.Styleable.GaugeView_showInnerRim, SHOW_INNER_RIM); mShowNeedle = typedArray.GetBoolean(Resource.Styleable.GaugeView_showNeedle, SHOW_NEEDLE); mShowScale = typedArray.GetBoolean(Resource.Styleable.GaugeView_showScale, SHOW_SCALE); mShowRanges = typedArray.GetBoolean(Resource.Styleable.GaugeView_showRanges, SHOW_RANGES); mShowText = typedArray.GetBoolean(Resource.Styleable.GaugeView_showText, SHOW_TEXT); mOuterShadowWidth = mShowOuterShadow ? typedArray.GetFloat(Resource.Styleable.GaugeView_outerShadowWidth, OUTER_SHADOW_WIDTH) : 0.0f; mOuterBorderWidth = mShowOuterBorder ? typedArray.GetFloat(Resource.Styleable.GaugeView_outerBorderWidth, OUTER_BORDER_WIDTH) : 0.0f; mOuterRimWidth = mShowOuterRim ? typedArray.GetFloat(Resource.Styleable.GaugeView_outerRimWidth, OUTER_RIM_WIDTH) : 0.0f; mInnerRimWidth = mShowInnerRim ? typedArray.GetFloat(Resource.Styleable.GaugeView_innerRimWidth, INNER_RIM_WIDTH) : 0.0f; mInnerRimBorderWidth = mShowInnerRim ? typedArray.GetFloat(Resource.Styleable.GaugeView_innerRimBorderWidth, INNER_RIM_BORDER_WIDTH) : 0.0f; mNeedleWidth = typedArray.GetFloat(Resource.Styleable.GaugeView_needleWidth, NEEDLE_WIDTH); mNeedleHeight = typedArray.GetFloat(Resource.Styleable.GaugeView_needleHeight, NEEDLE_HEIGHT); mScalePosition = (mShowScale || mShowRanges) ? typedArray.GetFloat(Resource.Styleable.GaugeView_scalePosition, SCALE_POSITION) : 0.0f; mScaleStartValue = typedArray.GetFloat(Resource.Styleable.GaugeView_scaleStartValue, SCALE_START_VALUE); mScaleEndValue = typedArray.GetFloat(Resource.Styleable.GaugeView_scaleEndValue, SCALE_END_VALUE); mScaleStartAngle = typedArray.GetFloat(Resource.Styleable.GaugeView_scaleStartAngle, SCALE_START_ANGLE); mScaleEndAngle = typedArray.GetFloat(Resource.Styleable.GaugeView_scaleEndAngle, 360.0f - mScaleStartAngle); mDivisions = typedArray.GetInteger(Resource.Styleable.GaugeView_divisions, SCALE_DIVISIONS); mSubdivisions = typedArray.GetInteger(Resource.Styleable.GaugeView_subdivisions, SCALE_SUBDIVISIONS); if (mShowRanges) { mTextShadowColor = typedArray.GetColor(Resource.Styleable.GaugeView_textShadowColor, TEXT_SHADOW_COLOR); string[] rangeValues = typedArray.GetTextArray(Resource.Styleable.GaugeView_rangeValues); string[] rangeColors = typedArray.GetTextArray(Resource.Styleable.GaugeView_rangeColors); ReadRanges(rangeValues, rangeColors); } if (mShowText) { int textValueId = typedArray.GetResourceId(Resource.Styleable.GaugeView_textValue, 0); string textValue = typedArray.GetString(Resource.Styleable.GaugeView_textValue); mTextValue = (0 < textValueId) ? context.GetString(textValueId) : (null != textValue) ? textValue : ""; int textUnitId = typedArray.GetResourceId(Resource.Styleable.GaugeView_textUnit, 0); string textUnit = typedArray.GetString(Resource.Styleable.GaugeView_textUnit); mTextUnit = (0 < textUnitId) ? context.GetString(textUnitId) : (null != textUnit) ? textUnit : ""; mTextValueColor = typedArray.GetColor(Resource.Styleable.GaugeView_textValueColor, TEXT_VALUE_COLOR); mTextUnitColor = typedArray.GetColor(Resource.Styleable.GaugeView_textUnitColor, TEXT_UNIT_COLOR); mTextShadowColor = typedArray.GetColor(Resource.Styleable.GaugeView_textShadowColor, TEXT_SHADOW_COLOR); mTextValueSize = typedArray.GetFloat(Resource.Styleable.GaugeView_textValueSize, TEXT_VALUE_SIZE); mTextUnitSize = typedArray.GetFloat(Resource.Styleable.GaugeView_textUnitSize, TEXT_UNIT_SIZE); } typedArray.Recycle(); }
public RVPIndicator(Context context, IAttributeSet attrs) : base(context, attrs) { mIndicatorWidth = Width / mTabVisibleCount; // 获得自定义属性 TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.RVPIndicator); mTabVisibleCount = a.GetInt(Resource.Styleable.RVPIndicator_item_count, D_TAB_COUNT); mTextColorNormal = a .GetColor(Resource.Styleable.RVPIndicator_text_color_normal, D_TEXT_COLOR_NORMAL); mTextColorHighlight = a.GetColor( Resource.Styleable.RVPIndicator_text_color_hightlight, D_TEXT_COLOR_HIGHLIGHT); mTextSize = a.GetDimensionPixelSize(Resource.Styleable.RVPIndicator_text_size, 16); mIndicatorColor = a.GetColor(Resource.Styleable.RVPIndicator_indicator_color, D_INDICATOR_COLOR); mIndicatorStyle = a.GetInt(Resource.Styleable.RVPIndicator_indicator_style, STYLE_LINE); Drawable drawable = a .GetDrawable(Resource.Styleable.RVPIndicator_indicator_src); if (drawable != null) { if (drawable is BitmapDrawable) { mBitmap = ((BitmapDrawable)drawable).Bitmap; } else if (drawable is NinePatchDrawable) { // .9图处理 Bitmap bitmap = Bitmap.CreateBitmap( drawable.IntrinsicWidth, drawable.IntrinsicHeight, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); drawable.SetBounds(0, 0, canvas.Width, canvas.Height); drawable.Draw(canvas); mBitmap = bitmap; } } else { mBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.heart_love); } a.Recycle(); /** * 设置画笔 */ mPaint = new Paint(); mPaint.AntiAlias = (true); mPaint.Color = new Color(mIndicatorColor); mPaint.SetStyle(Style.Fill); }
public PinWidget(Context context, IAttributeSet attribs, int defStyleAttr) : base(context, attribs, defStyleAttr) { ShouldRedraw = false; this.FillViewport = true; ScrollBarStyle = ScrollbarStyles.OutsideInset; TypedArray array = context.ObtainStyledAttributes(attribs, Resource.Styleable.PinView); var method = array.GetString(Resource.Styleable.PinView_onPinCompleted); PinListener = new PrivatePinListener(method, this); DigitCount = (uint)array.GetInt(Resource.Styleable.PinView_digitCount, PinDefaults.DIGIT_COUNT); DisplayMetrics metrics = Resources.DisplayMetrics; // Digit dimensions DigitWidth = array.GetDimensionPixelSize(Resource.Styleable.PinView_digitWidth, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.DIGIT_WIDTH, metrics)); DigitHeight = array.GetDimensionPixelSize(Resource.Styleable.PinView_digitHeight, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.DIGIT_HEIGHT, metrics)); DigitSpacing = array.GetDimensionPixelSize(Resource.Styleable.PinView_digitSpacing, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.DIGIT_SPACING, metrics)); TextSize = array.GetDimensionPixelSize(Resource.Styleable.PinView_textSize, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.TEXT_SIZE, metrics)); TypedValue resolvedColor = new TypedValue(); Resources.Theme theme = context.Theme; // Colors theme.ResolveAttribute(Android.Resource.Attribute.TextColorPrimary, resolvedColor, true); TextColor = array.GetColor(Resource.Styleable.PinView_textColor, resolvedColor.ResourceId > 0 ? ContextCompat.GetColor(context, resolvedColor.ResourceId) : resolvedColor.Data); DigitBorderColor = array.GetColor(Resource.Styleable.PinView_borderColor, TextColor); resolvedColor = new TypedValue(); theme.ResolveAttribute(Android.Resource.Attribute.ColorAccent, resolvedColor, true); AccentColor = array.GetColor(Resource.Styleable.PinView_accentColor, resolvedColor.ResourceId > 0 ? ContextCompat.GetColor(context, resolvedColor.ResourceId) : resolvedColor.Data); resolvedColor = new TypedValue(); theme.ResolveAttribute(Android.Resource.Attribute.WindowBackground, resolvedColor, true); DigitBackgroundColor = array.GetColor(Resource.Styleable.PinView_digitBackgroundColor, resolvedColor.ResourceId > 0 ? ContextCompat.GetColor(context, resolvedColor.ResourceId) : resolvedColor.Data); AccentHeight = (int)array.GetDimension(Resource.Styleable.PinView_accentHeight, TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.ACCENT_HEIGHT, metrics)); array.Recycle(); _mainLayout = new LinearLayout(Context); _pinInputField = new EditText(Context); var container = new FrameLayout(Context); container.AddView(_mainLayout); container.AddView(_pinInputField); this.AddView(container); ShouldRedraw = true; }
private void InitAttributes(IAttributeSet attrs) { TypedArray styleable = Context.ObtainStyledAttributes(attrs, Resource.Styleable.FloatingTextButton, 0, 0); text = styleable.GetString(Resource.Styleable.FloatingTextButton_floating_title); textColor = styleable.GetColor(Resource.Styleable.FloatingTextButton_floating_title_color, Color.Black); leftIcon = styleable.GetDrawable(Resource.Styleable.FloatingTextButton_floating_left_icon); background = styleable.GetColor(Resource.Styleable.FloatingTextButton_floating_background_color, Color.White); styleable.Recycle(); }
public ChipView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { TypedArray a = context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.ChipView, defStyleAttr, 0); if (a.HasValue(Resource.Styleable.ChipView_chip_text)) { _chipText = a.GetString(Resource.Styleable.ChipView_chip_text); } _hasIcon = a.GetBoolean(Resource.Styleable.ChipView_enable_icon, false); if (a.HasValue(Resource.Styleable.ChipView_chip_icon)) { _chipIcon = a.GetDrawable(Resource.Styleable.ChipView_chip_icon); } _closable = a.GetBoolean(Resource.Styleable.ChipView_closeable, false); _selectable = a.GetBoolean(Resource.Styleable.ChipView_chip_selectable, false); _backgroundColor = a.GetColor(Resource.Styleable.ChipView_chip_backgroundColor, ContextCompat.GetColor(context, Resource.Color.default_chip_background_color)); _selectedBackgroundColor = a.GetColor(Resource.Styleable.ChipView_chip_selectedBackgroundColor, ContextCompat.GetColor(context, Resource.Color.default_chip_background_clicked_color)); _textColor = a.GetColor(Resource.Styleable.ChipView_chip_text_color, ContextCompat.GetColor(context, Resource.Color.default_chip_text_color)); _selectedTextColor = a.GetColor(Resource.Styleable.ChipView_chip_selected_text_color, ContextCompat.GetColor(context, Resource.Color.default_chip_text_clicked_color)); _closeColor = a.GetColor(Resource.Styleable.ChipView_chip_close_color, ContextCompat.GetColor(context, Resource.Color.default_chip_close_inactive_color)); _selectedCloseColor = a.GetColor(Resource.Styleable.ChipView_chip_selected_close_color, ContextCompat.GetColor(context, Resource.Color.default_chip_close_clicked_color)); _cornerRadius = (int)a.GetDimension(Resource.Styleable.ChipView_chip_cornerRadius, Resources.GetDimension(Resource.Dimension.chip_height) / 2); _strokeSize = (int)a.GetDimension(Resource.Styleable.ChipView_chip_strokeSize, 0); _strokeColor = a.GetColor(Resource.Styleable.ChipView_chip_strokeColor, ContextCompat.GetColor(context, Resource.Color.default_chip_close_clicked_color)); if (a.HasValue(Resource.Styleable.ChipView_chip_iconText)) { _iconText = a.GetString(Resource.Styleable.ChipView_chip_iconText); } _iconTextColor = a.GetColor(Resource.Styleable.ChipView_chip_iconTextColor, ContextCompat.GetColor(context, Resource.Color.default_chip_background_clicked_color)); _iconTextBackgroundColor = a.GetColor(Resource.Styleable.ChipView_chip_iconTextBackgroundColor, ContextCompat.GetColor(context, Resource.Color.default_chip_close_clicked_color)); a.Recycle(); InitalizeViews(context); }
/** * Initializes paint objects and sets desired attributes. * @param Context Context * @param _attrs Attributes * @param _defStyle Default Style */ private void Init() { // Initialize paint objects _paint = new Paint { AntiAlias = true }; _paintBorder = new Paint { AntiAlias = true }; _paintSelectorBorder = new Paint { AntiAlias = true }; // Disable this view's hardware acceleration on Honeycomb and up (Needed for shadow effect) if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb) { SetLayerType(LayerType.Software, _paintBorder); SetLayerType(LayerType.Software, _paintSelectorBorder); } // load the styled attributes and set their properties TypedArray attributes = Context.ObtainStyledAttributes(_attrs, Resource.Styleable.CircularImageView, _defStyle, 0); // Check if border and/or border is enabled _hasBorder = attributes.GetBoolean(Resource.Styleable.CircularImageView_border, false); _hasSelector = attributes.GetBoolean(Resource.Styleable.CircularImageView_selector, false); // Set border properties if enabled if (_hasBorder) { int defaultBorderSize = (int)(2 * Context.Resources.DisplayMetrics.Density + 0.5f); SetBorderWidth(attributes.GetDimensionPixelOffset(Resource.Styleable.CircularImageView_border_width, defaultBorderSize)); SetBorderColor(attributes.GetColor(Resource.Styleable.CircularImageView_border_color, Color.White)); } // Set selector properties if enabled if (_hasSelector) { int defaultSelectorSize = (int)(2 * Context.Resources.DisplayMetrics.Density + 0.5f); SetSelectorColor(attributes.GetColor( Resource.Styleable.CircularImageView_selector_color, Color.Transparent)); SetSelectorStrokeWidth(attributes.GetDimensionPixelOffset(Resource.Styleable.CircularImageView_selector_stroke_width, defaultSelectorSize)); SetSelectorStrokeColor(attributes.GetColor(Resource.Styleable.CircularImageView_selector_stroke_color, Color.Blue)); } // Add shadow if enabled if (attributes.GetBoolean(Resource.Styleable.CircularImageView_shadow, false)) { SetShadow(attributes); } // We no longer need our attributes TypedArray, give it back to cache attributes.Recycle(); }
public CircleImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleImageView, defStyle, 0); mBorderWidth = a.GetDimensionPixelSize(Resource.Styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.GetColor(Resource.Styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_COLOR); //使用这个不报错 mBorderOverlay = a.GetBoolean(Resource.Styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY); mFillColor = a.GetColor(Resource.Styleable.CircleImageView_civ_border_overlay, DEFAULT_FILL_COLOR); //使用这个不报错 a.Recycle(); init(); }
public void ApplyTypedArray(TypedArray arr) { Gravity = (GravityFlags)arr.GetInt(Resource.Styleable.odometer_android_gravity, (int)Gravity); ShadowColor = arr.GetColor(Resource.Styleable.odometer_android_shadowColor, ShadowColor); ShadowDx = arr.GetFloat(Resource.Styleable.odometer_android_shadowDx, ShadowDx); ShadowDy = arr.GetFloat(Resource.Styleable.odometer_android_shadowDy, ShadowDy); ShadowRadius = arr.GetFloat(Resource.Styleable.odometer_android_shadowRadius, ShadowRadius); Text = arr.GetString(Resource.Styleable.odometer_android_text); TextColor = arr.GetColor(Resource.Styleable.odometer_android_textColor, TextColor); TextSize = arr.GetDimension(Resource.Styleable.odometer_android_textSize, TextSize); TextStyle = (TypefaceStyle)arr.GetInt(Resource.Styleable.odometer_android_textStyle, (int)TextStyle); }
private void Init(Context context, IAttributeSet attrs, int style) { Resources res = Resources; density = res.DisplayMetrics.Density; TypedArray a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.SlideToAction, style, 0); string tmp = a.GetString(Resource.Styleable.SlideToAction_slideToUnlockText); text = string.IsNullOrEmpty(tmp) ? text : tmp; rx = a.GetDimension(Resource.Styleable.SlideToAction_cornerRadiusX, rx); useDefaultCornerRadiusX = rx == 0; ry = a.GetDimension(Resource.Styleable.SlideToAction_cornerRadiusX, ry); useDefaultCornerRadiusY = ry == 0; backgroundColor = a.GetColor(Resource.Styleable.SlideToAction_slideToUnlockBackgroundColor, backgroundColor); textColor = a.GetColor(Resource.Styleable.SlideToAction_slideToUnlockTextColor, textColor); sliderColor = a.GetColor(Resource.Styleable.SlideToAction_sliderColor, sliderColor); cancelOnYExit = a.GetBoolean(Resource.Styleable.SlideToAction_cancelOnYExit, false); a.Recycle(); mRoundedRectPath = new Path(); mBackgroundPaint = new Paint(PaintFlags.AntiAlias); mBackgroundPaint.SetStyle(Paint.Style.Fill); mBackgroundPaint.Color = backgroundColor; mTextPaint = new Paint(PaintFlags.AntiAlias); mTextPaint.SetStyle(Paint.Style.Fill); mTextPaint.Color = textColor; mTextPaint.SetTypeface(Typeface.Create("Roboto-Thin", TypefaceStyle.Normal)); mSliderPaint = new Paint(PaintFlags.AntiAlias); mSliderPaint.SetStyle(Paint.Style.FillAndStroke); mSliderPaint.Color = sliderColor; mSliderPaint.StrokeWidth = 2 * density; if (!IsInEditMode) { // Edit mode does not support shadow layers // mSliderPaint.setShadowLayer(10.0f, 0.0f, 2.0f, 0xFF000000); //mSliderPaint.setMaskFilter(new EmbossMaskFilter(new float[]{1, 1, 1}, 0.4f, 10, 8.2f)); float[] direction = new float[] { 0.0f, -1.0f, 0.5f }; MaskFilter filter = new EmbossMaskFilter(direction, 0.8f, 15f, 1f); mSliderPaint.SetMaskFilter(filter); //mSliderPaint.setShader(new LinearGradient(8f, 80f, 30f, 20f, Color.RED,Color.WHITE, Shader.TileMode.MIRROR)); //mSliderPaint.setShader(new RadialGradient(8f, 80f, 90f, Color.RED,Color.WHITE, Shader.TileMode.MIRROR)); //mSliderPaint.setShader(new SweepGradient(80, 80, Color.RED, Color.WHITE)); //mSliderPaint.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.OUTER)); } }
protected override void UseStyleAttributes(TypedArray attrs) { var titleText = attrs.GetString(Resource.Styleable.SingleLineIconWithTextView_textForTitle); var titleTextColor = attrs.GetColor(Resource.Styleable.SingleLineIconWithTextView_textColorForTitle, -1); var titleTextSize = attrs.GetDimension(Resource.Styleable.SingleLineIconWithTextView_textSizeForTitle, -1); var titleTextStyle = attrs.GetInt(Resource.Styleable.SingleLineIconWithTextView_textStyleForTitle, (int)Enum.ToObject(typeof(TypefaceStyle), TypefaceStyle.Normal)); var titleTypeface = attrs.GetInt(Resource.Styleable.SingleLineIconWithTextView_typefaceForTitle, 0); var titleFontFamily = attrs.GetString(Resource.Styleable.SingleLineIconWithTextView_fontFamilyForTitle); var iconSrc = attrs.GetDrawable(Resource.Styleable.SingleLineIconWithTextView_iconSrc); var iconTint = attrs.GetColor(Resource.Styleable.SingleLineIconWithTextView_iconTint, -1); attrs.Recycle(); PrepareTextViewWithAttrValues(viewTitle, titleText, titleTextColor, titleTextSize, titleTextStyle, titleTypeface, titleFontFamily); PrepareIconViewWithAttrValues(iconSrc, iconTint); }
private void init(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) { mMinWidth = 24; mMaxWidth = 48; mMinHeight = 24; mMaxHeight = 48; TypedArray a = context.ObtainStyledAttributes( attrs, Resource.Styleable.AVLoadingIndicatorView, defStyleAttr, defStyleRes); mMinWidth = a.GetDimensionPixelSize(Resource.Styleable.AVLoadingIndicatorView_minWidth, mMinWidth); mMaxWidth = a.GetDimensionPixelSize(Resource.Styleable.AVLoadingIndicatorView_maxWidth, mMaxWidth); mMinHeight = a.GetDimensionPixelSize(Resource.Styleable.AVLoadingIndicatorView_minHeight, mMinHeight); mMaxHeight = a.GetDimensionPixelSize(Resource.Styleable.AVLoadingIndicatorView_maxHeight, mMaxHeight); string indicatorName = a.GetString(Resource.Styleable.AVLoadingIndicatorView_indicatorName); mIndicatorColor = a.GetColor(Resource.Styleable.AVLoadingIndicatorView_indicatorColor, Color.White); setIndicator(indicatorName); if (mIndicator == null) { setIndicator(DEFAULT_INDICATOR); } a.Recycle(); }
public static int GetThemeTextPrimaryInverseColor(Context context) { int color = -1; TypedArray arr = null; try { // Get the primary text color of the theme TypedValue typedValue = new TypedValue(); context.Theme.ResolveAttribute(Android.Resource.Attribute.TextColorPrimaryInverse, typedValue, true); arr = context.ObtainStyledAttributes(typedValue.Data, new int[] { Android.Resource.Attribute.TextColorPrimaryInverse }); color = arr.GetColor(0, -1); } catch (Exception e) { Log.Error(TAG + $".{nameof(GetThemeTextPrimaryInverseColor)}", e.Message); } finally { arr.Recycle(); } return(color); }
void Init(IAttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray attrValues = Context.ObtainStyledAttributes(attrs, Resource.Styleable.BlurView, defStyleAttr, defStyleRes); _overlayColor = attrValues.GetColor(Resource.Styleable.BlurView_overlayColor, Color.Transparent); attrValues.Recycle(); }
public RoundProgressBar(Context context, IAttributeSet attributeSet) : base(context, attributeSet) { TypedArray attributes = context.ObtainStyledAttributes (attributeSet, Resource.Styleable.RoundCornerProgressBar); mDefaultRoundConrnerWidth = attributes .GetDimensionPixelSize(Resource.Styleable.RoundCornerProgressBar_round_corner_width, Dip2px(Context, 4)); mRoundCornerBackgroundColor = attributes .GetColor(Resource.Styleable.RoundCornerProgressBar_round_corner_background_color, DEFAULT_BACKGROUND_COLOR); mRoundCornerProgressColor = attributes. GetColor(Resource.Styleable.RoundCornerProgressBar_round_corner_progress_color, DEFAULT_PROGRESS_COLOR); attributes.Recycle(); Init(); }
protected void SetDefaultBackgroundColor(IVisualElementRenderer renderer) { if (ChildView.BackgroundColor == Color.Default) { TypedArray colors = Context.Theme.ObtainStyledAttributes(new[] { global::Android.Resource.Attribute.ColorBackground }); renderer.View.SetBackgroundColor(new global::Android.Graphics.Color(colors.GetColor(0, 0))); } }
private void ApplyBackgroundColor(TypedArray attrs, int attributeIndex, View targetView) { if (attrs.HasValue(attributeIndex)) { int color = attrs.GetColor(attributeIndex, 0); targetView.SetBackgroundColor(new Color(color)); } }
private LayerDrawable createNormalDrawable(TypedArray attr) { LayerDrawable drawableNormal = (LayerDrawable) getDrawable(Resource.Drawable.rect_normal).Mutate(); GradientDrawable drawableTop = (GradientDrawable)drawableNormal.GetDrawable (0).Mutate (); drawableTop.SetCornerRadius(getCornerRadius()); int blueDark = getColor(Resource.Color.blue_pressed); int colorPressed = attr.GetColor(Resource.Styleable.FlatButton_pb_colorPressed, blueDark); drawableTop.SetColor(colorPressed); GradientDrawable drawableBottom = (GradientDrawable) drawableNormal.GetDrawable(1).Mutate(); drawableBottom.SetCornerRadius(getCornerRadius()); int blueNormal = getColor(Resource.Color.blue_normal); int colorNormal = attr.GetColor(Resource.Styleable.FlatButton_pb_colorNormal, blueNormal); drawableBottom.SetColor(colorNormal); return drawableNormal; }
private Drawable createPressedDrawable(TypedArray attr) { GradientDrawable drawablePressed = (GradientDrawable) getDrawable(Resource.Drawable.rect_pressed).Mutate(); drawablePressed.SetCornerRadius(getCornerRadius()); int blueDark = getColor(Resource.Color.blue_pressed); int colorPressed = attr.GetColor(Resource.Styleable.FlatButton_pb_colorPressed, blueDark); drawablePressed.SetColor(colorPressed); return drawablePressed; }