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); }
/** * 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(); }
/// <summary> /// 获取自定义属性 /// </summary> /// <param name="context"></param> /// <param name="attrs"></param> private void GetAttributes(Context context, IAttributeSet attrs) { TypedArray t_attrs = context.ObtainStyledAttributes(attrs, Resource.Styleable.RoundImageView); mBorderColor = t_attrs.GetColor(Resource.Styleable.RoundImageView_border_color, mBorderColor); int defalut = (int)(2 * context.Resources.DisplayMetrics.Density + 0.5f); mBorderWidth = t_attrs.GetDimensionPixelOffset(Resource.Styleable.RoundImageView_border_width, defalut); t_attrs.Recycle(); }
protected void HandleAttributes(Context context, IAttributeSet attrs) { try { TypedArray styledAttrs = context.ObtainStyledAttributes(attrs, Resource.Styleable.MaterialTextField); ANIMATION_DURATION = styledAttrs.GetInteger(Resource.Styleable.MaterialTextField_mtf_animationDuration, 400); OPEN_KEYBOARD_ON_FOCUS = styledAttrs.GetBoolean(Resource.Styleable.MaterialTextField_mtf_openKeyboardOnFocus, true); labelColor = styledAttrs.GetColor(Resource.Styleable.MaterialTextField_mtf_labelColor, -1); imageDrawableId = styledAttrs.GetResourceId(Resource.Styleable.MaterialTextField_mtf_image, -1); cardCollapsedHeight = styledAttrs.GetDimensionPixelOffset(Resource.Styleable.MaterialTextField_mtf_cardCollapsedHeight, context.Resources.GetDimensionPixelOffset(Resource.Dimension.mtf_cardHeight_initial)); hasFocus = styledAttrs.GetBoolean(Resource.Styleable.MaterialTextField_mtf_hasFocus, false); backgroundColor = styledAttrs.GetColor(Resource.Styleable.MaterialTextField_mtf_backgroundColor, -1); styledAttrs.Recycle(); } catch (Exception e) { e.PrintStackTrace(); } }
public int GetDimensionPixelOffset(int index, int defValue) { return(_array.GetDimensionPixelOffset(index, defValue)); }
/** * Retrieve attributes from the MaterialViewPager * @param context * @param attrs */ public void HandleAttributes(Context context, IAttributeSet attrs) { try { TypedArray styledAttrs = context.ObtainStyledAttributes(attrs, Resource.Styleable.MaterialViewPager); { HeaderLayoutId = styledAttrs.GetResourceId(Resource.Styleable.MaterialViewPager_viewpager_header, -1); } { PagerTitleStripId = styledAttrs.GetResourceId(Resource.Styleable.MaterialViewPager_viewpager_pagerTitleStrip, -1); if (PagerTitleStripId == -1) { PagerTitleStripId = Resource.Layout.material_view_pager_pagertitlestrip_standard; } } { LogoLayoutId = styledAttrs.GetResourceId(Resource.Styleable.MaterialViewPager_viewpager_logo, -1); LogoMarginTop = styledAttrs.GetDimensionPixelSize(Resource.Styleable.MaterialViewPager_viewpager_logoMarginTop, 0); } { Color = styledAttrs.GetColor(Resource.Styleable.MaterialViewPager_viewpager_color, 0); } { HeaderHeightPx = styledAttrs.GetDimensionPixelOffset(Resource.Styleable.MaterialViewPager_viewpager_headerHeight, 200); HeaderHeight = Math.Round(Utils.PxToDp(HeaderHeightPx, context)); //convert to dp } { HeaderAdditionalHeight = styledAttrs.GetDimensionPixelOffset(Resource.Styleable.MaterialViewPager_viewpager_headerAdditionalHeight, 60); } { HeaderAlpha = styledAttrs.GetFloat(Resource.Styleable.MaterialViewPager_viewpager_headerAlpha, 0.5f); } { ParallaxHeaderFactor = styledAttrs.GetFloat(Resource.Styleable.MaterialViewPager_viewpager_parallaxHeaderFactor, 1.5f); ParallaxHeaderFactor = Math.Max(ParallaxHeaderFactor, 1); //min=1 } { HideToolbarAndTitle = styledAttrs.GetBoolean(Resource.Styleable.MaterialViewPager_viewpager_hideToolbarAndTitle, false); HideLogoWithFade = styledAttrs.GetBoolean(Resource.Styleable.MaterialViewPager_viewpager_hideLogoWithFade, false); } { EnableToolbarElevation = styledAttrs.GetBoolean(Resource.Styleable.MaterialViewPager_viewpager_enableToolbarElevation, false); } { DisplayToolbarWhenSwipe = styledAttrs.GetBoolean(Resource.Styleable.MaterialViewPager_viewpager_displayToolbarWhenSwipe, false); } { ToolbarTransparent = styledAttrs.GetBoolean(Resource.Styleable.MaterialViewPager_viewpager_transparentToolbar, false); } { AnimatedHeaderImage = styledAttrs.GetBoolean(Resource.Styleable.MaterialViewPager_viewpager_animatedHeaderImage, true); } { DisableToolbar = styledAttrs.GetBoolean(Resource.Styleable.MaterialViewPager_viewpager_disableToolbar, false); } styledAttrs.Recycle(); } catch (Exception) { // ignored } }