我创建了一个包含RelativeLayout
和EditText
的简单自定义视图:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edt_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
同时我已经在res/values/attrs.xml
中添加了一些自定义属性,在我的自定义视图构造函数中检索这些属性,一切都运行良好。
现在,我想在我的自定义视图中检索EditText
默认属性,例如我想在自定义视图中获取android:text
属性。
我的自定义视图类 (简化版):
public class CustomEditText extends RelativeLayout {
private int panCount;
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs,
R.styleable.CustomEditText, 0, 0);
try {
this.panCount = typedArray.getInt(R.styleable.CustomEditText_panCount, 16);
} finally {
typedArray.recycle();
}
}
}
我怎样才能在不重新声明
res/values/attrs.xml
中的文本属性的情况下实现这一点?
CustomEditText
添加你的styleable
文件? - tynn