让LabeledSpinner一个设置样式(RES /价值/ attrs.xml )
<declare-styleable name="LabeledSpinner">
<attr name="text" format="string"/>
</declare-styleable>
在你LabeledSpinner
public LabeledSpinner(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LabeledSpinner);
String text = a.getString(R.styleable.LabeledSpinner_text);
a.recycle();
}
注意,在LabeledSpinner
的text
属性是用作LabeledSpinner_text
。
现在,在您的布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourpackage="http://schemas.android.com/apk/res/com.package">
<com.package.LabeledSpinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yourpackage:text="This is where your text goes"/>
</LinearLayout>
这应该做的!