android.content.Context.obtainStyledAttributes()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(229)

本文整理了Java中android.content.Context.obtainStyledAttributes()方法的一些代码示例,展示了Context.obtainStyledAttributes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.obtainStyledAttributes()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:obtainStyledAttributes

Context.obtainStyledAttributes介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
 super(context, attrs, defStyle);

 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyCustomView, defStyle, 0);

 String str = a.getString(R.styleable.MyCustomView_my_custom_attribute);

 //do something with str

 a.recycle();
}

代码示例来源:origin: stackoverflow.com

public MyCustomElement(Context context, AttributeSet attrs) {
  super(context, attrs);

  TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MyCustomElement, 0, 0);
  try {
    distanceExample = ta.getDimension(R.styleable.MyCustomElement_distanceExample, 100.0f);
  } finally {
    ta.recycle();
  }
  // ...
}

代码示例来源:origin: daimajia/AndroidSwipeLayout

public DividerItemDecoration(Context context, AttributeSet attrs) {
  final TypedArray a = context
      .obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider});
  mDivider = a.getDrawable(0);
  a.recycle();
}

代码示例来源:origin: naman14/Timber

public LayoutParams(Context c, AttributeSet attrs) {
  super(c, attrs);
  final TypedArray a = c.obtainStyledAttributes(attrs, ATTRS);
  a.recycle();
}

代码示例来源:origin: nickbutcher/plaid

public LiftOff(Context context, AttributeSet attrs) {
  super(context, attrs);
  final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LiftOff);
  initialElevation = ta.getDimension(R.styleable.LiftOff_initialElevation, 0f);
  finalElevation = ta.getDimension(R.styleable.LiftOff_finalElevation, 0f);
  ta.recycle();
}

代码示例来源:origin: nickbutcher/plaid

public StartAnimatable(Context context, AttributeSet attrs) {
  super(context, attrs);
  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StartAnimatable);
  Drawable drawable = a.getDrawable(R.styleable.StartAnimatable_android_src);
  a.recycle();
  if (drawable instanceof Animatable) {
    animatable = (Animatable) drawable;
  } else {
    throw new IllegalArgumentException("Non-Animatable resource provided.");
  }
}

代码示例来源:origin: umano/AndroidSlidingUpPanel

public LayoutParams(Context c, AttributeSet attrs) {
    super(c, attrs);
    final TypedArray ta = c.obtainStyledAttributes(attrs, ATTRS);
    if (ta != null) {
      this.weight = ta.getFloat(0, 0);
      ta.recycle();
    }
  }
}

代码示例来源:origin: stackoverflow.com

public ImageAdapter(Context c) {
  mContext = c;
  TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
  mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
  a.recycle();
}

代码示例来源:origin: rey5137/material

public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PopupWindow, defStyleAttr, 0);
  mOverlapAnchor = a.getBoolean(R.styleable.PopupWindow_overlapAnchor, false);
  a.recycle();
  
}

代码示例来源:origin: nickbutcher/plaid

public ReflowText(Context context, AttributeSet attrs) {
  super(context, attrs);
  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ReflowText);
  velocity = a.getDimensionPixelSize(R.styleable.ReflowText_velocity, velocity);
  minDuration = a.getInt(R.styleable.ReflowText_minDuration, (int) minDuration);
  maxDuration = a.getInt(R.styleable.ReflowText_maxDuration, (int) maxDuration);
  staggerDelay = a.getInt(R.styleable.ReflowText_staggerDelay, (int) staggerDelay);
  freezeFrame = a.getBoolean(R.styleable.ReflowText_freezeFrame, false);
  a.recycle();
}

代码示例来源:origin: scwang90/SmartRefreshLayout

public TwoLevelHeader(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  mSpinnerStyle = SpinnerStyle.FixedBehind;
  TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.TwoLevelHeader);
  mMaxRage = ta.getFloat(R.styleable.TwoLevelHeader_srlMaxRage, mMaxRage);
  mFloorRage = ta.getFloat(R.styleable.TwoLevelHeader_srlFloorRage, mFloorRage);
  mRefreshRage = ta.getFloat(R.styleable.TwoLevelHeader_srlRefreshRage, mRefreshRage);
  mFloorDuration = ta.getInt(R.styleable.TwoLevelHeader_srlFloorDuration, mFloorDuration);
  mEnableTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnableTwoLevel, mEnableTwoLevel);
  mEnablePullToCloseTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnablePullToCloseTwoLevel, mEnablePullToCloseTwoLevel);
  ta.recycle();
}

代码示例来源:origin: koral--/android-gif-drawable

GifViewAttributes(final View view, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
  final TypedArray gifViewAttributes = view.getContext().obtainStyledAttributes(attrs, R.styleable.GifView, defStyleAttr, defStyleRes);
  freezesAnimation = gifViewAttributes.getBoolean(R.styleable.GifView_freezesAnimation, false);
  mLoopCount = gifViewAttributes.getInt(R.styleable.GifView_loopCount, -1);
  gifViewAttributes.recycle();
}

代码示例来源:origin: H07000223/FlycoTabLayout

private void obtainAttributes(Context context, AttributeSet attrs) {
  TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MsgView);
  backgroundColor = ta.getColor(R.styleable.MsgView_mv_backgroundColor, Color.TRANSPARENT);
  cornerRadius = ta.getDimensionPixelSize(R.styleable.MsgView_mv_cornerRadius, 0);
  strokeWidth = ta.getDimensionPixelSize(R.styleable.MsgView_mv_strokeWidth, 0);
  strokeColor = ta.getColor(R.styleable.MsgView_mv_strokeColor, Color.TRANSPARENT);
  isRadiusHalfHeight = ta.getBoolean(R.styleable.MsgView_mv_isRadiusHalfHeight, false);
  isWidthHeightEqual = ta.getBoolean(R.styleable.MsgView_mv_isWidthHeightEqual, false);
  ta.recycle();
}

代码示例来源:origin: square/leakcanary

public MoreDetailsView(Context context, AttributeSet attrs) {
 super(context, attrs);
 Resources resources = getResources();
 iconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
 float strokeSize = resources.getDimensionPixelSize(R.dimen.leak_canary_more_stroke_width);
 iconPaint.setStrokeWidth(strokeSize);
 // This lint check doesn't work for libraries which have a common prefix.
 @SuppressLint("CustomViewStyleable") //
   TypedArray a =
   context.obtainStyledAttributes(attrs, R.styleable.leak_canary_MoreDetailsView);
 int plusColor =
   a.getColor(R.styleable.leak_canary_MoreDetailsView_leak_canary_plus_color, Color.BLACK);
 a.recycle();
 iconPaint.setColor(plusColor);
}

代码示例来源:origin: nickbutcher/plaid

@Keep
public StaggeredDistanceSlide(Context context, AttributeSet attrs) {
  super(context, attrs);
  final TypedArray a =
      context.obtainStyledAttributes(attrs, R.styleable.StaggeredDistanceSlide);
  spread = a.getInteger(R.styleable.StaggeredDistanceSlide_spread, spread);
  a.recycle();
}

代码示例来源:origin: nickbutcher/plaid

public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundView,
      defStyle, 0);
  final Drawable d = a.getDrawable(R.styleable.ForegroundView_android_foreground);
  if (d != null) {
    setForeground(d);
  }
  a.recycle();
}

代码示例来源:origin: hdodenhof/CircleImageView

public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
  mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH);
  mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR);
  mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);
  mCircleBackgroundColor = a.getColor(R.styleable.CircleImageView_civ_circle_background_color, DEFAULT_CIRCLE_BACKGROUND_COLOR);
  a.recycle();
  init();
}

代码示例来源:origin: nickbutcher/plaid

public void setCollapsedTextAppearance(int resId) {
  TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
  if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
    mCollapsedTextColor = a.getColor(
        R.styleable.TextAppearance_android_textColor, mCollapsedTextColor);
  }
  if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
    mCollapsedTextSize = a.getDimensionPixelSize(
        R.styleable.TextAppearance_android_textSize, (int) mCollapsedTextSize);
  }
  a.recycle();
  recalculate();
}

代码示例来源:origin: nickbutcher/plaid

public void setExpandedTextAppearance(int resId) {
  TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
  if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
    mExpandedTextColor = a.getColor(
        R.styleable.TextAppearance_android_textColor, mExpandedTextColor);
  }
  if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
    mExpandedTextSize = a.getDimensionPixelSize(
        R.styleable.TextAppearance_android_textSize, (int) mExpandedTextSize);
  }
  a.recycle();
  recalculate();
}

代码示例来源:origin: scwang90/SmartRefreshLayout

public FunGameHitBlockHeader(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FunGameHitBlockHeader);
  speed = ta.getInt(R.styleable.FunGameHitBlockHeader_fghBallSpeed, DensityUtil.dp2px(SPEED));
  blockHorizontalNum = ta.getInt(R.styleable.FunGameHitBlockHeader_fghBlockHorizontalNum, BLOCK_HORIZONTAL_NUM);
  ta.recycle();
  blockPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  blockPaint.setStyle(Paint.Style.FILL);
  BALL_RADIUS = DensityUtil.dp2px(4);
}

相关文章

Context类方法