private void init(Context context,AttributeSet attrs){
if(attrs==null) return ;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.inputView);
inputIcon= typedArray.getResourceId(R.styleable. inputView_input_icon,R.mipmap.logo);
inputHint=typedArray.getString(R.styleable. inputView_input_hint);
isPassword=typedArray.getBoolean(R.styleable. inputView_is_password,false);
typedArray.recycle();
}检查变量名是否一致
<resources> <declare-styleable name="inputView"> <attr name="input_icon" format="reference"></attr> <attr name="input_hint" format="string"/> </declare-styleable> </resources>