public void GridViewParams(TypedArray paramTypedArray) { HorizontalSpacing = paramTypedArray.GetDimensionPixelSize(0, horizontalSpacing); VerticalSpacing = paramTypedArray.GetDimensionPixelSize(1, verticalSpacing); NumColumns = paramTypedArray.GetInt(3, numColumns); ColumnWidth = paramTypedArray.GetDimensionPixelSize(2, columnWidth); }
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(); }
private void handleTypedArray(Context context, IAttributeSet attrs) { if (attrs == null) { return; } TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleIndicator); this.mIndicatorWidth = typedArray.GetDimensionPixelSize(Resource.Styleable.CircleIndicator_ci_width, -1); this.mIndicatorHeight = typedArray.GetDimensionPixelSize(Resource.Styleable.CircleIndicator_ci_height, -1); this.mIndicatorMargin = typedArray.GetDimensionPixelSize(Resource.Styleable.CircleIndicator_ci_margin, -1); this.mAnimatorResId = typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_animator, Resource.Animator.scale_with_alpha); this.mAnimatorReverseResId = typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_animator_reverse, 0); this.mIndicatorBackgroundResId = typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_drawable, Resource.Drawable.white_radius); this.mIndicatorUnselectedBackgroundResId = typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_drawable_unselected, this.mIndicatorBackgroundResId); Android.Widget.Orientation orientation = (Android.Widget.Orientation)typedArray.GetInt(Resource.Styleable.CircleIndicator_ci_orientation, -1); Orientation = (orientation == Android.Widget.Orientation.Vertical ? Android.Widget.Orientation.Vertical : Android.Widget.Orientation.Horizontal); int gravity = typedArray.GetInt(Resource.Styleable.CircleIndicator_ci_gravity, -1); SetGravity((gravity >= 0 ? (GravityFlags)gravity : GravityFlags.Center)); typedArray.Recycle(); }
private void init(IAttributeSet attrs) { TypedArray typedArray = Context.ObtainStyledAttributes(attrs, Resource.Styleable.timeline_style); mMarker = typedArray.GetDrawable(Resource.Styleable.timeline_style_marker); mStartLine = typedArray.GetDrawable(Resource.Styleable.timeline_style_line); mEndLine = typedArray.GetDrawable(Resource.Styleable.timeline_style_line); mMarkerSize = typedArray.GetDimensionPixelSize(Resource.Styleable.timeline_style_markerSize, Utils.dpToPx(20, mContext)); mLineSize = typedArray.GetDimensionPixelSize(Resource.Styleable.timeline_style_lineSize, Utils.dpToPx(2, mContext)); mLineOrientation = typedArray.GetInt(Resource.Styleable.timeline_style_lineOrientation, 1); mLinePadding = typedArray.GetDimensionPixelSize(Resource.Styleable.timeline_style_linePadding, 0); mMarkerInCenter = typedArray.GetBoolean(Resource.Styleable.timeline_style_markerInCenter, true); typedArray.Recycle(); if (mMarker == null) { mMarker = mContext.Resources.GetDrawable(Resource.Drawable.marker); } if (mStartLine == null && mEndLine == null) { mStartLine = new ColorDrawable(mContext.Resources.GetColor(Android.Resource.Color.DarkerGray)); mEndLine = new ColorDrawable(mContext.Resources.GetColor(Android.Resource.Color.DarkerGray)); } }
private void init(IAttributeSet attrs, int defStyle) { TypedArray a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.ColorBars, defStyle, 0); Resources b = Context.Resources; mBarThickness = a.GetDimensionPixelSize( Resource.Styleable.ColorBars_bar_thickness, b.GetDimensionPixelSize(Resource.Dimension.bar_thickness)); mBarLength = a.GetDimensionPixelSize(Resource.Styleable.ColorBars_bar_length, b.GetDimensionPixelSize(Resource.Dimension.bar_length)); mPreferredBarLength = mBarLength; mBarPointerRadius = a.GetDimensionPixelSize( Resource.Styleable.ColorBars_bar_pointer_radius, b.GetDimensionPixelSize(Resource.Dimension.bar_pointer_radius)); mBarPointerHaloRadius = a.GetDimensionPixelSize( Resource.Styleable.ColorBars_bar_pointer_halo_radius, b.GetDimensionPixelSize(Resource.Dimension.bar_pointer_halo_radius)); mOrientation = a.GetBoolean( Resource.Styleable.ColorBars_bar_orientation_horizontal, ORIENTATION_DEFAULT); int n = a.IndexCount; for (int i = 0; i < n; i++) { int attributeIndex = a.GetIndex(i); switch (attributeIndex) { case Resource.Attribute.bar_corner_radius: case Resource.Styleable.ColorBars_bar_corner_radius: try { mCornerRadius = a.GetFloat(attributeIndex, CORNER_RADIUS_DEFAULT); } catch (Exception e) { System.Console.Error.WriteLine(e + ": " + e.Message); } break; default: break; } } a.Recycle(); mBarPaint = new Paint(PaintFlags.AntiAlias); mBarPaint.SetShader(shader); mBarPointerPosition = (mBarLength / 2) + mBarPointerHaloRadius; mBarPointerHaloPaint = new Paint(PaintFlags.AntiAlias); mBarPointerHaloPaint.Color = (Color.Black); mBarPointerHaloPaint.Alpha = (0x50); mBarPointerPaint = new Paint(PaintFlags.AntiAlias); mBarPointerPaint.Color = new Color(unchecked ((int)(0xff81ff00))); mPosToSVFactor = 1 / ((float)mBarLength / 2); mSVToPosFactor = ((float)mBarLength / 2) / 1; }
public void GridViewParams(TypedArray paramTypedArray) { this.HorizontalSpacing = paramTypedArray.GetDimensionPixelSize(0, 4); this.VerticalSpacing = paramTypedArray.GetDimensionPixelSize(1, 4); this.NumColumns = paramTypedArray.GetInt(3, 10); this.ColumnWidth = paramTypedArray.GetDimensionPixelSize(2, 48); }
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 Init(IAttributeSet attrs) { TypedArray typedArray = Context.ObtainStyledAttributes(attrs, Resource.Styleable.timeline_style); mMarker = typedArray.GetDrawable(Resource.Styleable.timeline_style_marker); mStartLine = typedArray.GetDrawable(Resource.Styleable.timeline_style_line); mEndLine = typedArray.GetDrawable(Resource.Styleable.timeline_style_line); mMarkerSize = typedArray.GetDimensionPixelSize(Resource.Styleable.timeline_style_marker_size, 25); mLineSize = typedArray.GetDimensionPixelSize(Resource.Styleable.timeline_style_line_size, 2); typedArray.Recycle(); if (mMarker == null) { mMarker = mContext.Resources.GetDrawable(Resource.Drawable.marker); } }
public BoundedFrameLayout(Context context, IAttributeSet attrs = null) : base(context, attrs) { TypedArray a = context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.BoundedFrameLayout, 0, 0); try { boundedWidth = a.GetDimensionPixelSize(Resource.Styleable.BoundedFrameLayout_bounded_width, 0); boundedHeight = a.GetDimensionPixelSize(Resource.Styleable.BoundedFrameLayout_bounded_height, 0); } finally { a.Recycle(); } }
public BottomSheet4StateBehaviour(Context context, IAttributeSet attrs) : base(context, attrs) { using (TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.BottomSheetBehavior_Layout)) { PeekHeight = a.GetDimensionPixelSize(Resource.Styleable.BottomSheetBehavior_Layout_behavior_peekHeight, 0); Hideable = a.GetBoolean(Resource.Styleable.BottomSheetBehavior_Layout_behavior_hideable, false); } /** * Getting the anchorPoint... */ AnchorPoint = DefaultAnchorPoint > PeekHeight ? DefaultAnchorPoint : 0; Collapsible = true; using (TypedArray a1 = context.ObtainStyledAttributes(attrs, Resource.Styleable.CustomBottomSheetBehavior)) { AnchorPoint = (int)a1.GetDimension(Resource.Styleable.CustomBottomSheetBehavior_anchorPoint, DefaultAnchorPoint); // _state = a1.GetInt(Resource.Styleable.CustomBottomSheetBehavior_defaultState, StateCollapsed); _state = a1.GetInt(Resource.Styleable.CustomBottomSheetBehavior_defaultState, StateAnchorPoint); } ViewConfiguration configuration = ViewConfiguration.Get(context); _minimumVelocity = configuration.ScaledMinimumFlingVelocity; _dragCallback = new ViewDragHelperCallback(this); }
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); } } }
public MaxWidthLinearLayout(Android.Content.Context context, IAttributeSet attrs) : base(context, attrs) { TypedArray a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.MaxWidthLinearLayout); maxWidth = a.GetDimensionPixelSize(Resource.Styleable.MaxWidthLinearLayout_maxWidth, Int32.MaxValue); }
bool TryGetTextAppearance(int appearance, out double val) { val = 0; try { using (var value = new TypedValue()) { if (_context.Theme.ResolveAttribute(appearance, value, true)) { var textSizeAttr = new[] { Resource.Attribute.TextSize }; const int indexOfAttrTextSize = 0; using (TypedArray array = _context.ObtainStyledAttributes(value.Data, textSizeAttr)) { val = _context.FromPixels(array.GetDimensionPixelSize(indexOfAttrTextSize, -1)); return(true); } } } } catch (Exception ex) { Internals.Log.Warning("Xamarin.Forms.Platform.Android.AndroidPlatformServices", "Error retrieving text appearance: {0}", ex); } return(false); }
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 SlidingTabLayoutPlus(Context context, IAttributeSet attrs) : base(context, attrs, 0) { this.mContext = context; SetFitsSystemWindows(true); SetWillNotDraw(false);//重写onDraw方法,需要调用这个方法来清除flag SetClipChildren(false); SetClipToPadding(false); this.mContext = context; mTabsContainer = new LinearLayout(context); AddView(mTabsContainer); obtainAttributes(context, attrs); var height = attrs.GetAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");// model.GetValue("layout_height");// .GetAttributeValue("http://schemas.android.com/apk/res/android", "layout_height"); if (height.Equals(ViewGroup.LayoutParams.MatchParent + "")) { } else if (height.Equals(ViewGroup.LayoutParams.WrapContent + "")) { } else { int[] systemAttrs = { Android.Resource.Attribute.LayoutHeight }; TypedArray a = context.ObtainStyledAttributes(attrs, systemAttrs); mHeight = a.GetDimensionPixelSize(0, ViewGroup.LayoutParams.WrapContent); a.Recycle(); } }
bool TryGetTextAppearance(int appearance, out double val) { val = 0; try { using (var value = new TypedValue()) { var context = Forms.MauiContext.Context; if (context.Theme.ResolveAttribute(appearance, value, true)) { var textSizeAttr = new[] { AndroidResource.Attribute.TextSize }; const int indexOfAttrTextSize = 0; using (TypedArray array = context.ObtainStyledAttributes(value.Data, textSizeAttr)) { val = context.FromPixels(array.GetDimensionPixelSize(indexOfAttrTextSize, -1)); return(true); } } } } catch (Exception ex) { Application.Current?.FindMauiContext()?.CreateLogger <FontNamedSizeService>()? .LogWarning(ex, "Error retrieving text appearance"); } return(false); }
private void init(Context context, Android.Util.IAttributeSet attrs, int defStyle) { LayoutInflater.From(context).Inflate(Resource.Layout.sat_main, this, true); imgMain = FindViewById <ImageView>(Resource.Id.sat_main); if (attrs != null) { TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.SatelliteMenu, defStyle, 0); satelliteDistance = typedArray.GetDimensionPixelSize(Resource.Styleable.SatelliteMenu_satelliteDistance, DEFAULT_SATELLITE_DISTANCE); totalSpacingDegree = typedArray.GetFloat(Resource.Styleable.SatelliteMenu_totalSpacingDegree, DEFAULT_TOTAL_SPACING_DEGREES); closeItemsOnClick = typedArray.GetBoolean(Resource.Styleable.SatelliteMenu_closeOnClick, DEFAULT_CLOSE_ON_CLICK); expandDuration = typedArray.GetInt(Resource.Styleable.SatelliteMenu_expandDuration, DEFAULT_EXPAND_DURATION); //float satelliteDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 170, getResources().getDisplayMetrics()); typedArray.Recycle(); } mainRotateLeft = SatelliteAnimationCreator.createMainButtonAnimation(context); mainRotateRight = SatelliteAnimationCreator.createMainButtonInverseAnimation(context); mainRotateLeft.SetAnimationListener(this); mainRotateRight.SetAnimationListener(this); imgMain.Click += (s, e) => { onClick(); }; internalItemClickListener = new InternalSatelliteOnClickListener(this); }
private void init(Context context, IAttributeSet attrs) { CoreUtility.ExecuteMethod("init", delegate() { mGestureListener = new CustomGestureListener(this); mDragHelperCallback = new CustomViewDragHelper(this); if (attrs != null && context != null) { TypedArray a = context.Theme.ObtainStyledAttributes( attrs, Resource.Styleable.SwipeRevealLayout, 0, 0 ); mDragEdge = a.GetInteger(Resource.Styleable.SwipeRevealLayout_dragEdge, DRAG_EDGE_LEFT); mMinFlingVelocity = a.GetInteger(Resource.Styleable.SwipeRevealLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY); mMode = a.GetInteger(Resource.Styleable.SwipeRevealLayout_mode, MODE_NORMAL); mMinDistRequestDisallowParent = a.GetDimensionPixelSize( Resource.Styleable.SwipeRevealLayout_minDistRequestDisallowParent, dpToPx(DEFAULT_MIN_DIST_REQUEST_DISALLOW_PARENT) ); } mDragHelper = ViewDragHelper.Create(this, 1.0f, mDragHelperCallback); mDragHelper.SetEdgeTrackingEnabled(ViewDragHelper.EdgeAll); mGestureDetector = new GestureDetectorCompat(context, mGestureListener); }); }
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(); } } }
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; }
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); }
private void ApplyPadding(TypedArray attrs, int attributeIndex, View[] targetViews) { int padding = attrs.GetDimensionPixelSize(attributeIndex, -1); if (padding > -1) { ApplyPadding(padding, targetViews); } }
public LayoutParams(Context c, IAttributeSet attrs) : base(c, attrs) { TypedArray a = c.ObtainStyledAttributes(attrs, Resource.Styleable.superslim_GridSLM); mNumColumns = a.GetInt(Resource.Styleable.superslim_GridSLM_slm_grid_numColumns, AUTO_FIT); mColumnWidth = a.GetDimensionPixelSize(Resource.Styleable.superslim_GridSLM_slm_grid_columnWidth, -1); a.Recycle(); }
private int GetViewPadding(Android.App.AlertDialog.Builder builder) { TypedArray attr = builder.Context.ObtainStyledAttributes( new int[] { Android.Resource.Attribute.ListPreferredItemPaddingLeft }); int padding = attr.GetDimensionPixelSize(0, 1); attr.Recycle(); return(padding); }
/// <summary> /// 获取自定义属性 /// </summary> /// <param name="context"></param> /// <param name="attrs"></param> private void GetAttributes(Context context, IAttributeSet attrs) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleImageView); mBorderWidth = a.GetDimensionPixelSize(Resource.Styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.GetColor(Resource.Styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR); mBorderOverlay = a.GetBoolean(Resource.Styleable.CircleImageView_border_overlay, DEFAULT_BORDER_OVERLAY); a.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 CircleImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleImageView, defStyle, 0); _borderWidth = a.GetDimensionPixelSize(Resource.Styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.GetColor(Resource.Styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR); a.Recycle(); Init(); }
private void loadAttributes(IAttributeSet attrs, Context context) { if (attrs != null && context != null) { TypedArray typedArray = context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.CompactCalendarView, 0, 0); try { currentDayBackgroundColor = typedArray.GetColor(Resource.Styleable.CompactCalendarView_compactCalendarCurrentDayBackgroundColor, currentDayBackgroundColor); calenderTextColor = typedArray.GetColor(Resource.Styleable.CompactCalendarView_compactCalendarTextColor, calenderTextColor); currentSelectedDayBackgroundColor = typedArray.GetColor(Resource.Styleable.CompactCalendarView_compactCalendarCurrentSelectedDayBackgroundColor, currentSelectedDayBackgroundColor); calenderBackgroundColor = typedArray.GetColor(Resource.Styleable.CompactCalendarView_compactCalendarBackgroundColor, calenderBackgroundColor); textSize = typedArray.GetDimensionPixelSize(Resource.Styleable.CompactCalendarView_compactCalendarTextSize, (int)TypedValue.ApplyDimension(ComplexUnitType.Sp, textSize, context.Resources.DisplayMetrics)); targetHeight = typedArray.GetDimensionPixelSize(Resource.Styleable.CompactCalendarView_compactCalendarTargetHeight, (int)TypedValue.ApplyDimension(ComplexUnitType.Sp, targetHeight, context.Resources.DisplayMetrics)); } finally { typedArray.Recycle(); } } }
private void Init(Context context, IAttributeSet attributes) { if (attributes != null) { int[] attributesArray = { Android.Resource.Attribute.ColumnWidth }; TypedArray array = context.ObtainStyledAttributes(attributes, attributesArray); _columnWidth = array.GetDimensionPixelSize(0, -1); array.Recycle(); } _manager = new GridLayoutManager(Context, 2); SetLayoutManager(_manager); }
public TitleImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon); TypedArray typedArray = Context.Theme.ObtainStyledAttributes(attrs, Resource.Styleable.TitleImageView, defStyle, 0); int count = typedArray.IndexCount; try { for (int i = 0; i < count; i++) { int index = typedArray.GetIndex(i); switch (index) { case Resource.Styleable.TitleImageView_image: image = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon); //image = BitmapFactory.DecodeResource(Resources, typedArray.GetResourceId(index, Resource.Drawable.Icon)); break; case Resource.Styleable.TitleImageView_imageScaleType: imageScaleType = (ImageScale)typedArray.GetInt(index, 0); break; case Resource.Styleable.TitleImageView_titleText: titleText = typedArray.GetString(index); break; case Resource.Styleable.TitleImageView_titleTextColor: titleTextColor = typedArray.GetColor(index, Color.Black); break; case Resource.Styleable.TitleImageView_titleTextSize: //获取尺寸三个方法的介绍:http://my.oschina.net/ldhy/blog/496420 titleTextSize = typedArray.GetDimensionPixelSize(index, (int)TypedValue.ApplyDimension(ComplexUnitType.Sp, 16, Resources.DisplayMetrics)); break; default: break; } } } catch (System.Exception ex) { throw ex; } finally { typedArray.Recycle(); } Init(); }