Android 自定义组合控件

1, you need to add this kind of code to the constructors of your custom view which must extend ViewGroup, and the parameter attachToRoot must be true.

    LayoutInflater.from(context).inflate(R.layout.yourLayout, this, true);

 

2,If you want to add your custom declared style, you may need to declare your custom namespace, for example,

    xmlns:wytings="http://schemas.android.com/apk/res-auto"

You will need to use this style in Java code and below code is what you need. By the way, typeArray should be recycled if not used.

    TypedArray typeArray = context.obtainStyledAttributes(attrs, R.styleable.yourStyle);

你可能感兴趣的:(Android 自定义组合控件)