本文整理汇总了Java中android.content.Context.obtainStyledAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Context.obtainStyledAttributes方法的具体用法?Java Context.obtainStyledAttributes怎么用?Java Context.obtainStyledAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.obtainStyledAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: obtainMutableAttrList
import android.content.Context; //导入方法依赖的package包/类
/**
* 通过传入的属性,获取支持的自定义属性MutableAttr列表
* @param context
* @param attrs
* @return
*/
public List<MutableAttr> obtainMutableAttrList(Context context, AttributeSet attrs, List<MutableAttr> viewAttrs) {
if (mCustomAttrList == null || mCustomAttrList.isEmpty()) {
return new ArrayList<>();
}
if (viewAttrs == null) {
viewAttrs = new ArrayList<>();
}
Collections.sort(mCustomAttrList);
int size = mCustomAttrList.size();
int[] customAttrs = new int[size];
for (int i = 0; i < size; i++) {
customAttrs[i] = mCustomAttrList.get(i);
}
TypedArray a = context.obtainStyledAttributes(attrs, customAttrs);
int N = a.getIndexCount();
for (int j = 0; j < N; j++) {
int index = a.getIndex(j);
int resId = a.getResourceId(index, 0);
MutableAttr mutableAttr = MutableAttrFactory.create(context, customAttrs[j], resId);
if (mutableAttr != null) {
viewAttrs.add(mutableAttr);
}
}
return viewAttrs;
}
示例2: Rotate3dAnimation
import android.content.Context; //导入方法依赖的package包/类
public Rotate3dAnimation (Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Rotate3dAnimation);
mFromDegrees = a.getFloat(R.styleable.Rotate3dAnimation_fromDeg, 0.0f);
mToDegrees = a.getFloat(R.styleable.Rotate3dAnimation_toDeg, 0.0f);
mRollType = a.getInt(R.styleable.Rotate3dAnimation_rollType, ROLL_BY_X);
Description d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotX));
mPivotXType = d.type;
mPivotXValue = d.value;
d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotY));
mPivotYType = d.type;
mPivotYValue = d.value;
a.recycle();
initializePivotPoint();
}
示例3: initAttrs
import android.content.Context; //导入方法依赖的package包/类
private void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) {
mCircleRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, mMetrics);
mSpaceRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, mMetrics);
mAnnulusWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, mMetrics);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadarView, defStyleAttr, 0);
mRadarColor = a.getColor(R.styleable.RadarView_radarview_radarColor, Color.GRAY);
mCircleRadius = a.getDimension(R.styleable.RadarView_radarview_circleRadius, mCircleRadius);
mSpaceRadius = a.getDimension(R.styleable.RadarView_radarview_spaceRadius, mSpaceRadius);
mAnnulusNum = a.getInt(R.styleable.RadarView_radarview_annulusNum, mAnnulusNum);
mAnnulusWidth = a.getDimension(R.styleable.RadarView_radarview_annulusWidth, mAnnulusWidth);
mAnnulusColor = a.getColor(R.styleable.RadarView_radarview_annulusColor, Color.GRAY);
int rotateRateIndex = a.getInt(R.styleable.RadarView_radarview_rotateRate, 1);
switch (rotateRateIndex) {
case 0:
mRotateRate = RotateRate.SLOW;
break;
case 1:
mRotateRate = RotateRate.FAST;
break;
}
mReverse = a.getBoolean(R.styleable.RadarView_radarview_reverse, false);
a.recycle();
}
示例4: SnackbarBaseLayout
import android.content.Context; //导入方法依赖的package包/类
SnackbarBaseLayout(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackbarLayout);
if (a.hasValue(R.styleable.SnackbarLayout_android_elevation)) {
ViewCompat.setElevation(this, a.getDimensionPixelSize(
R.styleable.SnackbarLayout_android_elevation, 0));
}
a.recycle();
setClickable(true);
}
示例5: setup
import android.content.Context; //导入方法依赖的package包/类
private void setup(Context context, AttributeSet attrs) {
setDialogLayoutResource(R.layout.slider_preference_dialog);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SliderPreference);
try {
setSummary(a.getTextArray(R.styleable.SliderPreference_android_summary));
} catch (Exception e) {
// Do nothing
}
a.recycle();
}
示例6: RImageView
import android.content.Context; //导入方法依赖的package包/类
public RImageView(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RImageView);
mMaskDrawable = typedArray.getDrawable(R.styleable.RImageView_r_mask_drawable);
maskGravity = typedArray.getInt(R.styleable.RImageView_r_mask_gravity, maskGravity);
maskScaleX = typedArray.getFloat(R.styleable.RImageView_r_mask_scale_x, maskScaleX);
maskScaleY = typedArray.getFloat(R.styleable.RImageView_r_mask_scale_y, maskScaleY);
typedArray.recycle();
}
示例7: SolidLayout
import android.content.Context; //导入方法依赖的package包/类
public SolidLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (attrs != null) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SolidLayout, 0, 0);
mPreventParentTouchEvents = a.getBoolean(R.styleable.SolidLayout_preventParentTouchEvents, mPreventParentTouchEvents);
mPreventChildTouchEvents = a.getBoolean(R.styleable.SolidLayout_preventChildTouchEvents, mPreventChildTouchEvents);
a.recycle();
}
}
示例8: DStateLayout
import android.content.Context; //导入方法依赖的package包/类
public DStateLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mInflater = LayoutInflater.from(context);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DStateLayout, defStyleAttr,
R.style.DStateLayout_Style);
mEmptyImage = a.getResourceId(R.styleable.DStateLayout_llEmptyImage, NO_ID);
mEmptyText = a.getString(R.styleable.DStateLayout_llEmptyText);
mErrorImage = a.getResourceId(R.styleable.DStateLayout_llErrorImage, NO_ID);
mErrorText = a.getString(R.styleable.DStateLayout_llErrorText);
mRetryText = a.getString(R.styleable.DStateLayout_llRetryText);
mTextColor = a.getColor(R.styleable.DStateLayout_llTextColor, 0xff999999);
mTextSize = a.getDimensionPixelSize(R.styleable.DStateLayout_llTextSize, dp2px(16));
mButtonTextColor = a.getColor(R.styleable.DStateLayout_llButtonTextColor, 0xff999999);
mButtonTextSize = a.getDimensionPixelSize(R.styleable.DStateLayout_llButtonTextSize, dp2px(16));
mButtonBackground = a.getDrawable(R.styleable.DStateLayout_llButtonBackground);
mEmptyResId =
a.getResourceId(R.styleable.DStateLayout_llEmptyResId, R.layout.d_state_layout_empty);
mLoadingResId =
a.getResourceId(R.styleable.DStateLayout_llLoadingResId, R.layout.d_state_layout_loading);
mErrorResId =
a.getResourceId(R.styleable.DStateLayout_llErrorResId, R.layout.d_state_layout_error);
a.recycle();
}
示例9: init
import android.content.Context; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ColorIconView);
int color = typedArray.getColor(R.styleable.ColorIconView_civ_color, 0);
setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
typedArray.recycle();
}
示例10: init
import android.content.Context; //导入方法依赖的package包/类
public void init(Context context, AttributeSet attrs) {
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ClipViewLayout);
//获取剪切框距离左右的边距, 默认为50dp
mHorizontalPadding = array.getDimensionPixelSize(R.styleable.ClipViewLayout_mHorizontalPadding,
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()));
//获取裁剪框边框宽度,默认1dp
int clipBorderWidth = array.getDimensionPixelSize(R.styleable.ClipViewLayout_clipBorderWidth,
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
//裁剪框类型(圆或者矩形)
int clipType = array.getInt(R.styleable.ClipViewLayout_clipType, 1);
//回收
array.recycle();
clipView = new ClipView(context);
//设置裁剪框类型
clipView.setClipType(clipType == 1 ? ClipView.ClipType.CIRCLE : ClipView.ClipType.RECTANGLE);
//设置剪切框边框
clipView.setClipBorderWidth(clipBorderWidth);
//设置剪切框水平间距
clipView.setmHorizontalPadding(mHorizontalPadding);
imageView = new ImageView(context);
//相对布局布局参数
android.view.ViewGroup.LayoutParams lp = new LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.MATCH_PARENT);
this.addView(imageView, lp);
this.addView(clipView, lp);
}
示例11: VideoControlView
import android.content.Context; //导入方法依赖的package包/类
public VideoControlView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.VideoControlView);
int itemColor = ta.getColor(R.styleable.VideoControlView_itemColor, DEFAULT_ITEM_COLOR);
ta.recycle();
// setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(itemColor);
mPath = new Path();
mDuration = DEFAULT_DURATION;
}
示例12: init
import android.content.Context; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs)
{
setWillNotDraw(false);
initEffectBridge();
// 初始化.
if (attrs != null)
{
TypedArray tArray = context.obtainStyledAttributes(attrs, R.styleable.MainUpView);// 获取配置属性
Drawable drawableUpRect = tArray.getDrawable(R.styleable.MainUpView_upImageRes); // 顶层图片.
Drawable drawableShadow = tArray.getDrawable(R.styleable.MainUpView_shadowImageRes); // 阴影图片.
setUpRectDrawable(drawableUpRect);
setShadowDrawable(drawableShadow);
tArray.recycle();
}
}
示例13: checkAppCompatTheme
import android.content.Context; //导入方法依赖的package包/类
public static void checkAppCompatTheme(Context context) {
TypedArray a = context.obtainStyledAttributes(APPCOMPAT_CHECK_ATTRS);
final boolean failed = !a.hasValue(0);
a.recycle();
if (failed) {
throw new IllegalArgumentException("You need to use a Theme.AppCompat theme "
+ "(or descendant) with the design library.");
}
}
示例14: IReaderGridLayout
import android.content.Context; //导入方法依赖的package包/类
public IReaderGridLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.IReaderGridLayout, defStyleAttr, 0);
mRowCount = a.getInt(R.styleable.IReaderGridLayout_iReaderRowCount, 2);
mColumnCount = a.getInt(R.styleable.IReaderGridLayout_iReaderColumnCount, 2);
mGap = a.getDimensionPixelSize(R.styleable.IReaderGridLayout_iReaderGap, 0);
a.recycle();
}
示例15: SettingItemView
import android.content.Context; //导入方法依赖的package包/类
public SettingItemView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SettingItemView);
this.mIcon = typedArray.getDrawable(1);
this.mTitle = typedArray.getString(2);
this.mSubTitle = typedArray.getString(3);
this.mTextIndicator = typedArray.getString(4);
this.mTopDivider = typedArray.getBoolean(0, false);
this.mBottomDivider = typedArray.getBoolean(5, false);
typedArray.recycle();
this.mView = LayoutInflater.from(getContext()).inflate(R.layout.qp, null);
addView(this.mView);
ButterKnife.inject((View) this);
}