自定义属性1.在atrr.xml中生名变量
如:<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="test">
<attr name="visible_tab_count" format="integer" />
</declare-styleable>
</resources>
2.在自定义控件代码中初始化下:
如:public viewpageindicator(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.test);
visiabletab = a.getInt(R.styleable.test_visible_tab_count, COUNT_TAB);
}
3.在配置文件中声明:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:zzzz="http://schemas.android.com/apk/res/com.example.viewpagertabk"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.example.viewpagertabk.viewpageindicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@android:color/holo_orange_dark"
android:orientation="horizontal"
zzzz:visible_tab_count="6" >
</com.example.viewpagertabk.viewpageindicator>