当前位置: 首页>>代码示例>>C#>>正文


C# Context.ObtainStyledAttributes方法代码示例

本文整理汇总了C#中Android.Content.Context.ObtainStyledAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Context.ObtainStyledAttributes方法的具体用法?C# Context.ObtainStyledAttributes怎么用?C# Context.ObtainStyledAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Content.Context的用法示例。


在下文中一共展示了Context.ObtainStyledAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DividerItemDecoration

 public DividerItemDecoration (Context context, int orientation)
 {
     var a = context.ObtainStyledAttributes (Attrs);
     divider = a.GetDrawable (0);
     a.Recycle();
     Orientation = orientation;
 }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:7,代码来源:DividerItemDecoration.cs

示例2: CircleImageView

		public CircleImageView(Context context, IAttributeSet attrs, int defStyle)
			: base(context, attrs, defStyle)
		{

			// init paint
			paint = new Paint();
			paint.AntiAlias = true;

			paintBorder = new Paint();
			paintBorder.AntiAlias = true;

			// load the styled attributes and set their properties
			TypedArray attributes = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircularImageView, defStyle, 0);

			if (attributes.GetBoolean(Resource.Styleable.CircularImageView_border, true))
			{
				int defaultBorderSize = (int)(4 * context.Resources.DisplayMetrics.Density+ 0.5f);
				BorderWidth = attributes.GetDimensionPixelOffset(Resource.Styleable.CircularImageView_border_width, defaultBorderSize);
				BorderColor = attributes.GetColor(Resource.Styleable.CircularImageView_border_color, Color.White);
			}

			if (attributes.GetBoolean(Resource.Styleable.CircularImageView_shadow, false))
			{
				addShadow();
			}
		}
开发者ID:scrafty614,项目名称:XamarinStudio_Example,代码行数:26,代码来源:CircleImageView.cs

示例3: GridView

        public GridView(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.GridView, defStyle, 0);

            int markupId = a.GetResourceId(Resource.Styleable.GridView_grid_markup, DefaultGridMarkupValue);
            if(markupId != DefaultGridMarkupValue)
            {
                ParseMarkupXml(markupId);
            }
            else
            {
                _rowDefinitions.Add(new GridDefinition());
                _columnDefinitions.Add(new GridDefinition());
            }
            foreach(var row in _rowDefinitions)
            {
                var rowInfo = new GridDefinitionMeasureInfo(row);
                _rowsInfo.Add(row, rowInfo);
                if(row.Length.IsStar)
                {
                    _heightStarSum += row.Length.Value;
                }
            }
            foreach(var column in _columnDefinitions)
            {
                var columnInfo = new GridDefinitionMeasureInfo(column);
                _columnsInfo.Add(column, columnInfo);
                if(column.Length.IsStar)
                {
                    _widthStarSum += column.Length.Value;
                }
            }
        }
开发者ID:ZuZuK,项目名称:GridView,代码行数:34,代码来源:GridView.cs

示例4: AnimatedPathView

		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 ();
			}

		}
开发者ID:Appercode,项目名称:monodroid-samples,代码行数:26,代码来源:AnimatedPathView.cs

示例5: MvxImageView

        public MvxImageView(Context context, IAttributeSet attrs)
            : base(context, attrs)
        {
            if (!Mvx.TryResolve(out _imageHelper))
            {
                MvxTrace.Error(
                    "No IMvxImageHelper registered - you must provide an image helper before you can use a MvxImageView");
            }
            else
            {
                _imageHelper.ImageChanged += ImageHelperOnImageChanged;
            }

            var typedArray = context.ObtainStyledAttributes(attrs,
                                                            MvxAndroidBindingResource.Instance
                                                                                     .ImageViewStylableGroupId);

            int numStyles = typedArray.IndexCount;
            for (var i = 0; i < numStyles; ++i)
            {
                int attributeId = typedArray.GetIndex(i);
                if (attributeId == MvxAndroidBindingResource.Instance.SourceBindId)
                {
                    ImageUrl = typedArray.GetString(attributeId);
                }
            }
            typedArray.Recycle();
        }
开发者ID:darkice-matt-crombie,项目名称:MvxSpinnerTest,代码行数:28,代码来源:MvxImageView.cs

示例6: SearchToolbar

        public SearchToolbar(Context context, IAttributeSet attrs, int defStyleAttr)
            : base(context, attrs, defStyleAttr)
        {
            binding = SearchToolbarBinding.Inflate(LayoutInflater.From(context), Resource.Layout.toolbar_search, this, true);

            if (!IsInEditMode)
            {
                var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SearchToolbar);

                try
                {
                    var focus = a.GetBoolean(Resource.Styleable.SearchToolbar_searchFocus, false);
                    var hintResId = a.GetResourceId(Resource.Styleable.SearchToolbar_searchHint, Resource.String.search_hint);
                    SetHint(hintResId);
                    if (focus)
                    {
                        binding.editSearch.RequestFocus();
                    }
                    else
                    {
                        ClearFocus();
                    }
                    ToggleCloseButtonVisible(false);
                    InitView();
                } finally {
                    a.Recycle();
                }
            }
        }
开发者ID:amay077,项目名称:DroidKaigi2016Xamarin,代码行数:29,代码来源:SearchToolbar.cs

示例7: ApplyCustomFont

        //applies font from XML
        public static void ApplyCustomFont(TextView view, Context context, IAttributeSet attrs)
        {
            TypedArray attributeArray = context.ObtainStyledAttributes (attrs, Resource.Styleable.CustomFont);

            string fontName = attributeArray.GetString (Resource.Styleable.CustomFont_font);
            int textStyle = attrs.GetAttributeIntValue (ANDROID_SCHEMA, "textStyle", 0);

            Typeface customFont = SelectTypeface (context, fontName);

            switch (textStyle) {
            case 1:
                view.SetTypeface (customFont, TypefaceStyle.Bold);
                break;
            case 2:
                view.SetTypeface (customFont, TypefaceStyle.Italic);
                break;
            case 3:
                view.SetTypeface (customFont, TypefaceStyle.BoldItalic);
                break;
            default:
                view.SetTypeface (customFont, TypefaceStyle.Normal);
                break;
            }

            attributeArray.Recycle ();
        }
开发者ID:FrederickEskens,项目名称:Totem,代码行数:27,代码来源:CustomFontHelper.cs

示例8: ParseAttributes

        /// <summary>
        /// Parses the binding attributes into MvxViewBindingTag.
        /// </summary>
        /// <returns>The tag with parsed values, null if no binding attributes found.</returns>
        protected MvxViewBindingTag ParseAttributes (Context context, IAttributeSet attrs)
        {
            var res = MvxAndroidBindingResource.Instance;
            IEnumerable<MvxBindingDescription> descriptions = null;

            using (var typedArray = context.ObtainStyledAttributes(
                    attrs, res.BindingStylableGroupId)) {

                int numStyles = typedArray.IndexCount;
                for (var i = 0; i < numStyles; ++i) {
                    var attributeId = typedArray.GetIndex (i);

                    if (attributeId == res.BindingBindId) {
                        try {
                            var bindingText = typedArray.GetString (attributeId);
                            descriptions = this.GetService<IMvxBindingDescriptionParser> ().Parse (bindingText);
                        } catch (Exception exception) {
                            MvxBindingTrace.Trace (
                                MvxTraceLevel.Error, "Exception thrown during the parsing the bindings {0}",
                                exception.ToLongString ());
                            throw;
                        }
                    }
                }
                typedArray.Recycle ();
            }

            if (descriptions != null) {
                return new MvxViewBindingTag (descriptions);
            }
            return null;
        }
开发者ID:JoanMiro,项目名称:MvxMod,代码行数:36,代码来源:MvxBindingInflater.cs

示例9: ReadRecyclerViewItemTemplateSelectorClassName

        private static string ReadRecyclerViewItemTemplateSelectorClassName(Context context, IAttributeSet attrs)
        {
            TryInitializeBindingResourcePaths();

            TypedArray typedArray = null;

            string className = string.Empty;
            try
            {
                typedArray = context.ObtainStyledAttributes(attrs, MvxRecyclerViewItemTemplateSelectorGroupId);
                int numberOfStyles = typedArray.IndexCount;

                for (int i = 0; i < numberOfStyles; ++i)
                {
                    var attributeId = typedArray.GetIndex(i);

                    if (attributeId == MvxRecyclerViewItemTemplateSelector)
                        className = typedArray.GetString(attributeId);
                }
            }
            finally
            {
                typedArray?.Recycle();
            }

            if (string.IsNullOrEmpty(className))
                return typeof (SingleItemDefaultTemplateSelector).FullName;

            return className;
        }
开发者ID:maxgrig,项目名称:MvvmCross-AndroidSupport,代码行数:30,代码来源:MvxRecyclerViewAttributeExtensions.cs

示例10: CirclePageIndicator

		public CirclePageIndicator(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
		{
			//Load defaults from resources
			var res = Resources;
			int defaultPageColor = res.GetColor(Resource.Color.default_circle_indicator_page_color);
			int defaultFillColor = res.GetColor(Resource.Color.default_circle_indicator_fill_color);
			int defaultOrientation = res.GetInteger(Resource.Integer.default_circle_indicator_orientation);
			int defaultStrokeColor = res.GetColor(Resource.Color.default_circle_indicator_stroke_color);
			float defaultStrokeWidth = res.GetDimension(Resource.Dimension.default_circle_indicator_stroke_width);
			float defaultRadius = res.GetDimension(Resource.Dimension.default_circle_indicator_radius);
			bool defaultCentered = res.GetBoolean(Resource.Boolean.default_circle_indicator_centered);
			bool defaultSnap = res.GetBoolean(Resource.Boolean.default_circle_indicator_snap);

			//Retrieve styles attributes
			var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CirclePageIndicator, defStyle, Resource.Style.Widget_CirclePageIndicator);

			mCentered = a.GetBoolean(Resource.Styleable.CirclePageIndicator_vpiCentered, defaultCentered);
			mOrientation = a.GetInt(Resource.Styleable.CirclePageIndicator_vpiOrientation, defaultOrientation);
			mPaintPageFill = new Paint(PaintFlags.AntiAlias);
			mPaintPageFill.SetStyle(Paint.Style.Fill);
			mPaintPageFill.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiPageColor, defaultPageColor);
			mPaintStroke = new Paint(PaintFlags.AntiAlias);
			mPaintStroke.SetStyle(Paint.Style.Stroke);
			mPaintFill = new Paint(PaintFlags.AntiAlias);
			mPaintFill.SetStyle(Paint.Style.Fill);
			mSnap = a.GetBoolean(Resource.Styleable.CirclePageIndicator_vpiSnap, defaultSnap);

			mRadius = a.GetDimension(Resource.Styleable.CirclePageIndicator_vpiRadius, defaultRadius);
			mPaintFill.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiFillColor, defaultFillColor);
			mPaintStroke.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiStrokeColor, defaultStrokeColor);
			mPaintStroke.StrokeWidth = a.GetDimension(Resource.Styleable.CirclePageIndicator_vpiStrokeWidth, defaultStrokeWidth);

			a.Recycle();

		}
开发者ID:alexrainman,项目名称:CarouselView,代码行数:35,代码来源:CirclePageIndicator.cs

示例11: BezelImageView

	    public BezelImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
		{
			// Attribute initialization
	        var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.BezelImageView, defStyle, 0);
	
	        mMaskDrawable = a.GetDrawable(Resource.Styleable.BezelImageView_maskDrawable);
	        if (mMaskDrawable == null) {
	            mMaskDrawable = Resources.GetDrawable(Resource.Drawable.bezel_mask);
	        }
	        mMaskDrawable.Callback = this;
	
	        mBorderDrawable = a.GetDrawable(Resource.Styleable.BezelImageView_borderDrawable);
	        if (mBorderDrawable == null) {
	            mBorderDrawable = Resources.GetDrawable(Resource.Drawable.bezel_border);
	        }
	        mBorderDrawable.Callback = this;
	
	        a.Recycle();
	
	        // Other initialization
	        mMaskedPaint = new Paint();
	        mMaskedPaint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcAtop));
	
	        mCopyPaint = new Paint();
		}
开发者ID:BratislavDimitrov,项目名称:monodroid-samples,代码行数:25,代码来源:BezelImageView.cs

示例12: MvxHorizontalGridView

		public MvxHorizontalGridView(Context context, IAttributeSet attrs, int defStyle, IMvxRecyclerAdapter adapter) : base(context, attrs, defStyle)
		{
			// Note: Any calling derived class passing a null adapter is responsible for setting
			// it's own itemTemplateId
			if (adapter == null)
				return;

			var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);

			adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;

			var typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.MvxHorizontalGridView);
			try
			{
				FocusFirstChildOnLaidOut = typedArray.GetBoolean(Resource.Styleable.MvxHorizontalGridView_FocusFirstChildOnLaidOut, false);
				if (FocusFirstChildOnLaidOut)
				{
					SetOnChildLaidOutListener(new MvxFocusFirstChildOnChildLaidOutListener());
				}
			}
			finally
			{
				typedArray.Recycle();
			}

			// We need this listener to get information about the currently _selected_ item
			// Overriding setter of base.SelectedPosition is not enough!
			OnChildViewHolderSelectedListener = new MvxOnChildViewHolderSelectedListener();
			SetOnChildViewHolderSelectedListener(OnChildViewHolderSelectedListener);
		}
开发者ID:lothrop,项目名称:MvvmCross-AndroidSupport,代码行数:31,代码来源:MvxHorizontalGridView.cs

示例13: LinePageIndicator

        public LinePageIndicator(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            if(IsInEditMode) return;

            var res = Resources;

            //Load defaults from resources
            var defaultSelectedColor = res.GetColor(Resource.Color.default_line_indicator_selected_color);
            var defaultUnselectedColor = res.GetColor(Resource.Color.default_line_indicator_unselected_color);
            var defaultLineWidth = res.GetDimension(Resource.Dimension.default_line_indicator_line_width);
            var defaultGapWidth = res.GetDimension(Resource.Dimension.default_line_indicator_gap_width);
            var defaultStrokeWidth = res.GetDimension(Resource.Dimension.default_line_indicator_stroke_width);
            var defaultCentered = res.GetBoolean(Resource.Boolean.default_line_indicator_centered);

            //Retrive styles attributes
            var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.LinePageIndicator, defStyle, 0);
            _centered = a.GetBoolean(Resource.Styleable.LinePageIndicator_centered, defaultCentered);
            _lineWidth = a.GetDimension(Resource.Styleable.LinePageIndicator_lineWidth, defaultLineWidth);
            _gapWidth = a.GetDimension(Resource.Styleable.LinePageIndicator_gapWidth, defaultGapWidth);
            StrokeWidth = a.GetDimension(Resource.Styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth);
            _paintUnSelected.Color = a.GetColor(Resource.Styleable.LinePageIndicator_unselectedColor,
                                                defaultUnselectedColor);
            _paintSelected.Color = a.GetColor(Resource.Styleable.LinePageIndicator_selectedColor, defaultSelectedColor);

            var background = a.GetDrawable(Resource.Styleable.LinePageIndicator_android_background);
            if (null != background)
                Background = background;

            a.Recycle();

            var configuration = ViewConfiguration.Get(context);
            _touchSlop = ViewConfigurationCompat.GetScaledPagingTouchSlop(configuration);
        }
开发者ID:SeeD-Seifer,项目名称:ViewPagerIndicator,代码行数:34,代码来源:LinePageIndicator.cs

示例14: SwipeLayout

        public SwipeLayout(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            IsSwipeEnabled = true;
            gestureDetector = new GestureDetector (Context, new SwipeDetector (this));
            mDragHelperCallback = new SwipeLayoutDragHelperCallback (this);

            mDragHelper = ViewDragHelper.Create(this, mDragHelperCallback);
            mTouchSlop = ViewConfiguration.Get(context).ScaledTouchSlop;

            TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SwipeLayout);
            int dragEdgeChoices = a.GetInt(Resource.Styleable.SwipeLayout_drag_edge, DRAG_RIGHT);
            mEdgeSwipesOffset[(int)DragEdge.Left] = a.GetDimension(Resource.Styleable.SwipeLayout_leftEdgeSwipeOffset, 0);
            mEdgeSwipesOffset[(int)DragEdge.Right] = a.GetDimension(Resource.Styleable.SwipeLayout_rightEdgeSwipeOffset, 0);
            mEdgeSwipesOffset[(int)DragEdge.Top] = a.GetDimension(Resource.Styleable.SwipeLayout_topEdgeSwipeOffset, 0);
            mEdgeSwipesOffset[(int)DragEdge.Bottom] = a.GetDimension(Resource.Styleable.SwipeLayout_bottomEdgeSwipeOffset, 0);
            ClickToClose = a.GetBoolean(Resource.Styleable.SwipeLayout_clickToClose, ClickToClose);

            if ((dragEdgeChoices & DRAG_LEFT) == DRAG_LEFT) {
                mDragEdges.Add(DragEdge.Left, null);
            }
            if ((dragEdgeChoices & DRAG_TOP) == DRAG_TOP) {
                mDragEdges.Add(DragEdge.Top, null);
            }
            if ((dragEdgeChoices & DRAG_RIGHT) == DRAG_RIGHT) {
                mDragEdges.Add(DragEdge.Right, null);
            }
            if ((dragEdgeChoices & DRAG_BOTTOM) == DRAG_BOTTOM) {
                mDragEdges.Add(DragEdge.Bottom, null);
            }
            int ordinal = a.GetInt(Resource.Styleable.SwipeLayout_show_mode, (int)ShowMode.PullOut);
            mShowMode = (ShowMode)System.Enum.ToObject(typeof(ShowMode), ordinal);
            a.Recycle();
        }
开发者ID:T-Rex,项目名称:demo-android-article-list,代码行数:34,代码来源:SwipeLayout.cs

示例15: RoundedImageView

        public RoundedImageView(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.RoundedImageView, defStyle, 0);

            int index = a.GetInt(Resource.Styleable.RoundedImageView_android_scaleType, -1);
            SetScaleType(index >= 0 ? ScaleTypes[index] : ScaleType.FitCenter);

            _cornerRadius = a.GetDimensionPixelSize(Resource.Styleable.RoundedImageView_corner_radius, -1);
            _borderWidth = a.GetDimensionPixelSize(Resource.Styleable.RoundedImageView_border_width, -1);

            // don't allow negative values for radius and border
            if (_cornerRadius < 0)
            {
                _cornerRadius = DefaultRadius;
            }
            if (_borderWidth < 0)
            {
                _borderWidth = DefaultBorderWidth;
            }

            _borderColor = a.GetColorStateList(Resource.Styleable.RoundedImageView_border_color) ??
                           ColorStateList.ValueOf(Color.Black);

            _mutateBackground = a.GetBoolean(Resource.Styleable.RoundedImageView_mutate_background, false);
            _isOval = a.GetBoolean(Resource.Styleable.RoundedImageView_oval, false);

            UpdateDrawableAttrs();
            UpdateBackgroundDrawableAttrs(true);

            a.Recycle();
        }
开发者ID:herrskytte,项目名称:RoundedImageView,代码行数:32,代码来源:RoundedImageView.cs


注:本文中的Android.Content.Context.ObtainStyledAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。