本文整理汇总了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;
}
示例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();
}
}
示例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;
}
}
}
示例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 ();
}
}
示例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();
}
示例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();
}
}
}
示例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 ();
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}