<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="BannerViewArray">
<attr name="startAndclose" format="boolean"></attr>
<attr name="startTime" format="integer"></attr>
</declare-styleable>
</resources>
public BannerViewArray(Context context, @Nullable AttributeSet attrs) {
this(context,attrs,0);
TypedArray ty = context.obtainStyledAttributes(attrs, R.styleable.BannerViewArray);
startAndClose = ty.getBoolean(R.styleable.BannerViewArray_startAndclose, false);
//获取时间值
bannerTime = ty.getInteger(R.styleable.BannerViewArray_startTime,1000);
ty.recycle();//释放
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:banner="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.example.app0928day03.BannerViewArray
android:id="@+id/banner"
banner:startAndclose="true"
banner:startTime="3000"
android:layout_width="match_parent"
android:layout_height="200dp"/>
</RelativeLayout>