在 Android 自定义视图中调用 obtainStyledAttributes() 的正确方法是什么
What is proper way to call obtainStyledAttributes() in Android custom views
有什么区别
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0);
和
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView, defStyleAttr, 0);
"defStyleAttr" 是
当前主题中的一个属性,它包含对为 TypedArray 提供默认值的样式资源的引用。可以为 0 以不查找默认值。
有什么区别
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0);
和
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomView, defStyleAttr, 0);
"defStyleAttr" 是 当前主题中的一个属性,它包含对为 TypedArray 提供默认值的样式资源的引用。可以为 0 以不查找默认值。