我在库项目(Spinnerbutton)中有一个自定义小部件,我想在应用程序项目中使用它.自定义小部件包含TextView,我想从我的应用程序项目将样式传递给该TextView.
这是我的attrs.xml(在库项目中):
和应用程序的布局:
以下是我尝试在Spinnerbutton类中读取自定义属性的方法:
public Spinnerbutton(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Spinnerbutton); int textStyleId = a.getResourceId( R.styleable.Spinnerbutton_myTextAppearence, -1); a.recycle(); }
textStyleId始终返回-1,因此该值不会从布局传递给类.
这有什么不对?