android styleable 资源在哪里,android模块开发中的styleable资源处理

该博客详细介绍了Android自定义View的实现过程,具体到CirclePageIndicator组件的构造函数,它从属性集中获取配置,如页面颜色、填充颜色、描边颜色、半径等,并设置默认值。博客内容涉及Android资源获取、属性解析以及自定义View的样式定制。
摘要由CSDN通过智能技术生成

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

//设定默认值

final Resources res = getResources();

final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);

final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);

final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);

final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);

final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);

final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);

final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);

final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

//Retrieve styles attributes

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

//获取xml属性,如果没有则使用默认值

mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);

mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);

mPaintPageFill.setStyle(Style.FILL);

mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));

mPaintStroke.setStyle(Style.STROKE);

mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));

mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));

mPaintFill.setStyle(Style.FILL);

mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));

mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);

mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

//回收属性内存

a.recycle();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值