我有一个自定义的ViewGroup,其中包含一个EditText。我希望在xml中为EditText设置inputType。但是我不想重新定义输入类型。我该怎么做?
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyEditText);
a.getInt(android.R.attr.inputType, EditorInfo.TYPE_NULL);
错误,原因是我的ViewGroup中没有inputType属性。
我还尝试了这个方法:
Caused by: java.lang.ArrayIndexOutOfBoundsException:
int[] attrsReuse = new int[] { android.R.attr.inputType /* index 0 */};
Resources.Theme theme = context.getTheme();
TypedArray ta = theme.obtainStyledAttributes(attrsReuse);
同样的错误。
有什么想法吗?谢谢!