After doing additional research, I realized that the default values ββcan be set in the constructor for the View
itself.
public class MyCustomView extends View { private float mCustomAttribute; public MyCustomView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MyCustomView); mCustomAttribute = array.getFloat(R.styleable.MyCustomView_customAttribute, 0.4f); array.recycle(); } }
The default value can also be loaded from the xml resource file, which can vary depending on the screen size, screen orientation, SDK version, etc.
source share