private void init(AttributeSet attrs) { TypedArray a=getContext().obtainStyledAttributes( attrs, R.styleable.MyCustomView); //Use a Log.i("test",a.getString( R.styleable.MyCustomView_android_text)); Log.i("test",""+a.getColor( R.styleable.MyCustomView_android_textColor, Color.BLACK)); Log.i("test",a.getString( R.styleable.MyCustomView_extraInformation)); //Don't forget this a.recycle(); }
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(); }
// The attributes you want retrieved int[] attrs = {android.R.attr.textColor, android.R.attr.background, android.R.attr.text}; // Parse MyCustomStyle, using Context.obtainStyledAttributes() TypedArray ta = obtainStyledAttributes(R.style.MyCustomStyle, attrs); // Fetch the text from your style like this. String text = ta.getString(2); // Fetching the colors defined in your style int textColor = ta.getColor(0, Color.BLACK); int backgroundColor = ta.getColor(1, Color.BLACK); // Do some logging to see if we have retrieved correct values Log.i("Retrieved text:", text); Log.i("Retrieved textColor as hex:", Integer.toHexString(textColor)); Log.i("Retrieved background as hex:", Integer.toHexString(backgroundColor)); // OH, and don't forget to recycle the TypedArray ta.recycle()
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(); }
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); }
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(); }
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(); }
public LayoutParams(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SmartRefreshLayout_Layout); backgroundColor = ta.getColor(R.styleable.SmartRefreshLayout_Layout_layout_srlBackgroundColor, backgroundColor); if (ta.hasValue(R.styleable.SmartRefreshLayout_Layout_layout_srlSpinnerStyle)) { spinnerStyle = SpinnerStyle.values()[ta.getInt(R.styleable.SmartRefreshLayout_Layout_layout_srlSpinnerStyle, SpinnerStyle.Translate.ordinal())]; } ta.recycle(); }
public TimelyView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TimelyView); textColor = typedArray.getColor(R.styleable.TimelyView_text_color, Color.BLACK); init(); }
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_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR); mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_border_overlay, DEFAULT_BORDER_OVERLAY); a.recycle(); init(); }
private int fetchAccentColor() { TypedValue typedValue = new TypedValue(); TypedArray a = mContext.obtainStyledAttributes(typedValue.data, new int[] { R.attr.colorAccent }); int color = a.getColor(0, 0); a.recycle(); return color; }
/** * Get the background color of the theme used for this activity. * * @return The background color of the current theme. */ public int getThemeBackgroundColor() { TypedArray array = mActivity.getTheme().obtainStyledAttributes( new int[] { android.R.attr.colorBackground }); int backgroundColor = array.getColor(0, 0xFF00FF); array.recycle(); return backgroundColor; }
/** * This method setups Paint object for the crop guidelines. */ @SuppressWarnings("deprecation") private void initCropGridStyle(@NonNull TypedArray a) { int cropGridStrokeSize = a.getDimensionPixelSize(R.styleable.ucrop_UCropView_ucrop_grid_stroke_size, getResources().getDimensionPixelSize(R.dimen.ucrop_default_crop_grid_stoke_width)); int cropGridColor = a.getColor(R.styleable.ucrop_UCropView_ucrop_grid_color, getResources().getColor(R.color.ucrop_color_default_crop_grid)); mCropGridPaint.setStrokeWidth(cropGridStrokeSize); mCropGridPaint.setColor(cropGridColor); mCropGridRowCount = a.getInt(R.styleable.ucrop_UCropView_ucrop_grid_row_count, DEFAULT_CROP_GRID_ROW_COUNT); mCropGridColumnCount = a.getInt(R.styleable.ucrop_UCropView_ucrop_grid_column_count, DEFAULT_CROP_GRID_COLUMN_COUNT); }
public int resolveColorAttr(@AttrRes int attrResId, @ColorRes int defResId) { mAttrs[0] = attrResId; TypedArray a = mTheme.obtainStyledAttributes(mAttrs); try { return a.getColor(0, resolveColorRes(defResId)); } finally { a.recycle(); } }
static int getAttrTintColor(Context context, AttributeSet attrs, int attr, int defaultValue) { final TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final int tintColor = ThemeUtils.replaceColor(context, a.getColor(0, defaultValue)); a.recycle(); return tintColor; }
public PlayTransition(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PlayTransition); setColor(a.getColor(R.styleable.PlayTransition_colorCT, getColor())); a.recycle(); }
public MountainSceneView(Context context, AttributeSet attrs) { super(context, attrs); mMountPaint.setAntiAlias(true); mMountPaint.setStyle(Paint.Style.FILL); mTrunkPaint.setAntiAlias(true); mBranchPaint.setAntiAlias(true); mBoarderPaint.setAntiAlias(true); mBoarderPaint.setStyle(Paint.Style.STROKE); mBoarderPaint.setStrokeWidth(2); mBoarderPaint.setStrokeJoin(Paint.Join.ROUND); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MountainSceneView); if (ta.hasValue(R.styleable.MountainSceneView_msvPrimaryColor)) { setPrimaryColor(ta.getColor(R.styleable.MountainSceneView_msvPrimaryColor, 0xff000000)); } mViewportHeight = ta.getDimensionPixelOffset(R.styleable.MountainSceneView_msvViewportHeight, 0); ta.recycle(); updateMountainPath(mMoveFactor, HEIGHT); updateTreePath(mMoveFactor, true); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public SpinKitView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SpinKitView, defStyleAttr, defStyleRes); mStyle = Style.values()[a.getInt(R.styleable.SpinKitView_SpinKit_Style, 0)]; mColor = a.getColor(R.styleable.SpinKitView_SpinKit_Color, Color.WHITE); a.recycle(); init(); setIndeterminate(true); }
static int getAttrColor(Context context, AttributeSet attrs, int attr, int defaultValue) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final int colorId = a.getResourceId(0, 0); final int value = colorId != 0 ? ThemeUtils.replaceColorById(context, colorId) : ThemeUtils.replaceColor(context, a.getColor(0, defaultValue)); a.recycle(); return value; }
@Override public void init(HTextView hTextView, AttributeSet attrs, int defStyle) { super.init(hTextView, attrs, defStyle); TypedArray typedArray = hTextView.getContext().obtainStyledAttributes(attrs, R.styleable.LineTextView); animationDuration = typedArray.getInt(R.styleable.LineTextView_animationDuration, DEFAULT_DURATION); lineColor = typedArray.getColor(R.styleable.LineTextView_lineColor, hTextView.getCurrentTextColor()); lineWidth = typedArray.getDimension(R.styleable.LineTextView_lineWidth, DEFAULT_LINE_WIDTH); typedArray.recycle(); }