1.在values ->attrs创建
<declare-styleable name="CircleView"> <attr name="circleColor" format="color" /> </declare-styleable>
2.在view 中 引用
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleView); circleColor = typedArray.getColor(R.styleable.CircleView_circleColor, Color.BLUE); typedArray.recycle();
3.在布局中使用即可
app:circleColor="#F22222"