我已经创建了一个包含RelativeLayout
一个简单的自定义视图自定义视图得到的Android默认属性和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
重新声明文本属性?
它是混淆你不使用你的观点在XML代码...!你确定你已经发布了最新的代码。检查这个答案:https://stackoverflow.com/a/8090772/7134908它可能会解决您的问题,在xml中设置值,并进入Java vode –
你可以添加'Customable文件''CustomEditText'? – tynn
[如何在自定义TextView中使用命名空间“android”获取属性的可能的重复](https://stackoverflow.com/questions/26486791/how-to-get-attributes-with-namespace-android-in-custom-textview ) –