In a custom view I can get the custom attrs value from the AttributeSet (shown below). But how do I get the Android attributes? For instance, how do I access android:background or android:text ? android.R.styleable isn’t allowed.
<mine.custom.RangeSeekBar
custom:selectedMinValue="2"
custom:selectedMaxValue="4"
android:background="@drawable/my_skin" />
public RangeSeekBar(Context context, AttributeSet attrs, int defStyle) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RangeSeekBar, defStyle, 0);
selectedMinValue = a.getInt(R.styleable.RangeSeekBar_selectedMinValue, selectedMinValue);
selectedMaxValue = a.getInt(R.styleable.RangeSeekBar_selectedMaxValue, selectedMaxValue);
minRangeValue = a.getInt(R.styleable.RangeSeekBar_minRangeValue, minRangeValue);
maxRangeValue = a.getInt(R.styleable.RangeSeekBar_maxRangeValue, maxRangeValue);
a.recycle();
}
Edit: Is this the standard way?
final String xmlns="http://schemas.android.com/apk/res/android";
int xmlRes = attrs.getAttributeResourceValue(xmlns, "background", -1);
String xmlText = attrs.getAttributeValue(xmlns, "text");
I guess we’ll go with this: