Android_declare-styleable _ properties of Custom Controls
1. simple instance
(1) define an attrs. xml file under the res/values File
(2) Layout File Usage
(3). custom control settings
public class MyTextView extends TextView {public MyTextView(Context context) {this(context, null);}public MyTextView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public MyTextView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.my);String str = a.getString(R.styleable.my_content);setText(str + "@@");a.recycle();}}
2. Other remarks
(1 ). the format in each attr should be of the specified type, string/integer/dimension/reference (reference R file)/color/enum/boolean. Multiple formats can be separated by |, all others are the same, instance enum
(2) XML namespace rules in the layout file, xmlns: toolbar = http://schemas.android.com/apk/res/?packagename]