下面列出了android.content.res.TypedArray#getTextArray() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public ListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ListPreference, 0, 0);
mEntries = a.getTextArray(R.styleable.ListPreference_entries);
mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
a.recycle();
/* Retrieve the Preference summary attribute since it's private
* in the Preference class.
*/
a = context.obtainStyledAttributes(attrs,
R.styleable.Preference, 0, 0);
mSummary = a.getString(R.styleable.Preference_summary);
a.recycle();
}
public LinearListView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R_styleable_LinearListView);
// Use the thickness specified, zero being the default
final int thickness = a.getDimensionPixelSize(
LinearListView_dividerThickness, 0);
if (thickness != 0) {
setDividerThickness(thickness);
}
CharSequence[] entries = a.getTextArray(LinearListView_entries);
if (entries != null) {
setAdapter(new ArrayAdapter<>(context,
android.R.layout.simple_list_item_1, entries));
}
a.recycle();
}
public MultiCheckPreference(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.ListPreference, defStyleAttr, defStyleRes);
mEntries = a.getTextArray(com.android.internal.R.styleable.ListPreference_entries);
if (mEntries != null) {
setEntries(mEntries);
}
setEntryValuesCS(a.getTextArray(
com.android.internal.R.styleable.ListPreference_entryValues));
a.recycle();
/* Retrieve the Preference summary attribute since it's private
* in the Preference class.
*/
a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.Preference, 0, 0);
mSummary = a.getString(com.android.internal.R.styleable.Preference_summary);
a.recycle();
}
public AbsSpinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
// Spinner is important by default, unless app developer overrode attribute.
if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
}
initAbsSpinner();
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.AbsSpinner, defStyleAttr, defStyleRes);
final CharSequence[] entries = a.getTextArray(R.styleable.AbsSpinner_entries);
if (entries != null) {
final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
context, R.layout.simple_spinner_item, entries);
adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
setAdapter(adapter);
}
a.recycle();
}
@Override
protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
super.init(context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);
mEntries = a.getTextArray(R.styleable.ListPreference_entries);
mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
a.recycle();
/* Retrieve the Preference summary attribute since it's private
* in the Preference class.
*/
// a=context.obtainStyledAttributes(attrs,
// R.styleable.Preference,defStyleAttr,defStyleRes);
// mSummary=a.getString(R.styleable.Preference_summary);
// a.recycle();
mSummary = super.getSummary() == null ? null : super.getSummary().toString();
}
public IconListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0);
CharSequence[] drawables;
try {
drawables = a.getTextArray(R.styleable.IconListPreference_icons);
} finally {
a.recycle();
}
for (CharSequence drawable : drawables) {
int resId = context.getResources().getIdentifier(drawable.toString(), "mipmap", context.getPackageName());
Drawable d = context.getResources().getDrawable(resId);
mEntryDrawables.add(d);
}
setWidgetLayoutResource(R.layout.view_icon);
}
public ListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);
mEntries = a.getTextArray(R.styleable.ListPreference_android_entries);
mEntryValues = a.getTextArray(R.styleable.ListPreference_android_entryValues);
a.recycle();
/* Retrieve the Preference summary attribute since it's private
* in the Preference class.
*/
a = context.obtainStyledAttributes(attrs,
R.styleable.Preference, defStyleAttr, defStyleRes);
mSummary = a.getString(R.styleable.Preference_android_summary);
a.recycle();
}
protected void init(Context context, AttributeSet attrs) {
rootView = inflate(context, R.layout.singlevalueinput_view, this);
titleTextView = rootView.findViewById(R.id.singlevalueinput_title);
valueEditText = rootView.findViewById(R.id.singlevalueinput_value);
unitSpinner = rootView.findViewById(R.id.singlevalueinput_unitSpinner);
commentTextView = rootView.findViewById(R.id.singlevalueinput_comment);
commentLayout = rootView.findViewById(R.id.singlevalueinput_commentLayout);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.SingleValueInputView,
0, 0);
try {
mShowUnit = a.getBoolean(R.styleable.SingleValueInputView_showUnit, false);
setShowUnit(mShowUnit);
mShowComment = a.getBoolean(R.styleable.SingleValueInputView_showComment, false);
setShowComment(mShowComment);
mTitle = a.getString(R.styleable.SingleValueInputView_title);
setTitle(mTitle);
mComment = a.getString(R.styleable.SingleValueInputView_comment);
setComment(mComment);
mValue = a.getString(R.styleable.SingleValueInputView_value);
setValue(mValue);
mType = a.getInteger(R.styleable.SingleValueInputView_type, 0);
setType(mType);
CharSequence[] entries = a.getTextArray(R.styleable.SingleValueInputView_units);
if (entries != null)
{
setUnits(entries);
}
} finally {
a.recycle();
}
}
public MultiSelectListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MultiSelectListPreference, 0, 0);
mEntries = a.getTextArray(R.styleable.MultiSelectListPreference_entries);
mEntryValues = a.getTextArray(R.styleable.MultiSelectListPreference_entryValues);
a.recycle();
}
private void readConstraintsFromXml(AttributeSet attrs) {
TypedArray a = getContext().getTheme().obtainStyledAttributes(
attrs,
R.styleable.CassowaryLayout,
0, 0);
try {
final CharSequence[] constraints = a.getTextArray(R.styleable.CassowaryLayout_constraints);
asyncSetup = a.getBoolean(R.styleable.CassowaryLayout_asyncSetup, asyncSetup);
aspectRatioFixed = a.getBoolean(R.styleable.CassowaryLayout_aspectRatioFixed, aspectRatioFixed);
aspectRatioWidthFactor = a.getFloat(R.styleable.CassowaryLayout_aspectRatioWidthFactor, aspectRatioWidthFactor);
aspectRatioHeightFactor = a.getFloat(R.styleable.CassowaryLayout_aspectRatioHeightFactor, aspectRatioHeightFactor);
log("readConstraintsFromXml asyncSetup " + asyncSetup );
if (asyncSetup) {
setupSolverAsync(constraints);
} else {
cassowaryModel.addConstraints(constraints);
state = State.PARSING_COMPLETE;
}
if (constraints == null) {
throw new RuntimeException("missing cassowary:constraints attribute in XML");
}
} finally {
a.recycle();
}
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
setNegativeButtonText(android.R.string.cancel);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPreference, defStyleAttr, defStyleRes);
mEntries = a.getTextArray(R.styleable.ListPreference_entries);
mEntryValues = a.getTextArray(R.styleable.ListPreference_entryValues);
a.recycle();
/* Retrieve the Preference summary attribute since it's private
* in the Preference class.
*/
a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.summary}, defStyleAttr, defStyleRes);
mSummary = a.getString(0);
a.recycle();
}
public MultiSelectDragListPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MultiSelectDragListPreference, 0, 0);
mEntries = a.getTextArray(R.styleable.MultiSelectDragListPreference_entries);
mEntryValues = a.getTextArray(R.styleable.MultiSelectDragListPreference_entryValues);
a.recycle();
}
public HListView( Context context, AttributeSet attrs, int defStyle ) {
super( context, attrs, defStyle );
TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.HListView, defStyle, 0 );
CharSequence[] entries = a.getTextArray( R.styleable.HListView_android_entries );
if ( entries != null ) {
setAdapter( new ArrayAdapter<CharSequence>( context, android.R.layout.simple_list_item_1, entries ) );
}
final Drawable d = a.getDrawable( R.styleable.HListView_android_divider );
if ( d != null ) {
// If a divider is specified use its intrinsic height for divider height
setDivider( d );
}
final Drawable osHeader = a.getDrawable( R.styleable.HListView_overScrollHeader );
if ( osHeader != null ) {
setOverscrollHeader( osHeader );
}
final Drawable osFooter = a.getDrawable( R.styleable.HListView_overScrollFooter );
if ( osFooter != null ) {
setOverscrollFooter( osFooter );
}
// Use the height specified, zero being the default
final int dividerWidth = a.getDimensionPixelSize( R.styleable.HListView_dividerWidth, 0 );
if ( dividerWidth != 0 ) {
setDividerWidth( dividerWidth );
}
mHeaderDividersEnabled = a.getBoolean( R.styleable.HListView_headerDividersEnabled, true );
mFooterDividersEnabled = a.getBoolean( R.styleable.HListView_footerDividersEnabled, true );
mMeasureWithChild = a.getInteger( R.styleable.HListView_measureWithChild, -1 );
Log.d( LOG_TAG, "mMeasureWithChild: " + mMeasureWithChild );
a.recycle();
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.list_preference, defStyleAttr, defStyleRes);
mEntries = a.getTextArray(R.styleable.list_preference_entry_arr);
mEntryValues = a.getTextArray(R.styleable.list_preference_value_arr);
mFormat = a.getString(R.styleable.list_preference_format_str);
a.recycle();
}
private void initAttrs(AttributeSet attrs) {
try {
TypedArray t = getContext().obtainStyledAttributes(attrs, R.styleable.RangeSeekBar);
seekBarMode = t.getInt(R.styleable.RangeSeekBar_rsb_mode, SEEKBAR_MODE_RANGE);
minProgress = t.getFloat(R.styleable.RangeSeekBar_rsb_min, 0);
maxProgress = t.getFloat(R.styleable.RangeSeekBar_rsb_max, 100);
minInterval = t.getFloat(R.styleable.RangeSeekBar_rsb_min_interval, 0);
gravity = t.getInt(R.styleable.RangeSeekBar_rsb_gravity, Gravity.TOP);
progressColor = t.getColor(R.styleable.RangeSeekBar_rsb_progress_color, 0xFF4BD962);
progressRadius = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_progress_radius, -1);
progressDefaultColor = t.getColor(R.styleable.RangeSeekBar_rsb_progress_default_color, 0xFFD7D7D7);
progressDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_progress_drawable, 0);
progressDefaultDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_progress_drawable_default, 0);
progressHeight = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_progress_height, Utils.dp2px(getContext(), 2));
tickMarkMode = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_mode, TRICK_MARK_MODE_NUMBER);
tickMarkGravity = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_gravity, TICK_MARK_GRAVITY_CENTER);
tickMarkLayoutGravity = t.getInt(R.styleable.RangeSeekBar_rsb_tick_mark_layout_gravity, Gravity.TOP);
tickMarkTextArray = t.getTextArray(R.styleable.RangeSeekBar_rsb_tick_mark_text_array);
tickMarkTextMargin = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_tick_mark_text_margin, Utils.dp2px(getContext(), 7));
tickMarkTextSize = (int) t.getDimension(R.styleable.RangeSeekBar_rsb_tick_mark_text_size, Utils.dp2px(getContext(), 12));
tickMarkTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressDefaultColor);
tickMarkInRangeTextColor = t.getColor(R.styleable.RangeSeekBar_rsb_tick_mark_text_color, progressColor);
steps = t.getInt(R.styleable.RangeSeekBar_rsb_steps, 0);
stepsColor = t.getColor(R.styleable.RangeSeekBar_rsb_step_color, 0xFF9d9d9d);
stepsRadius = t.getDimension(R.styleable.RangeSeekBar_rsb_step_radius, 0);
stepsWidth = t.getDimension(R.styleable.RangeSeekBar_rsb_step_width, 0);
stepsHeight = t.getDimension(R.styleable.RangeSeekBar_rsb_step_height, 0);
stepsDrawableId = t.getResourceId(R.styleable.RangeSeekBar_rsb_step_drawable, 0);
stepsAutoBonding = t.getBoolean(R.styleable.RangeSeekBar_rsb_step_auto_bonding, true);
t.recycle();
} catch (Exception e) {
e.printStackTrace();
}
}
private void parseAttributes(Context context, AttributeSet attrs, int defStyleAttr) {
drawInnerViews(context, attrs);
TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.QuestionBaseView);
int viewType = values.getInt(R.styleable.QuestionBaseView_view_type, 1);
setViewType(viewType);
String text = values.getString(R.styleable.QuestionBaseView_question);
setQuestion(text);
CharSequence[] answers = values.getTextArray(R.styleable.QuestionBaseView_entries);
if(answers != null) setAnswers(answers);
values.recycle();
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index)
{
final CharSequence[] defaultValues = a.getTextArray(index);
final int valueCount = defaultValues.length;
final List<String> result = new ArrayList<String>();
for (int i = 0; i < valueCount; i++)
{
result.add(defaultValues[i].toString());
}
return result;
}
@SuppressLint("RestrictedApi")
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
setInputType(InputType.TYPE_NULL);
setCursorVisible(false);
Drawable arrow = getResources().getDrawable(R.drawable.ic_arrow_drop_down_black_24dp);
arrow.setBounds(0, 0, arrow.getIntrinsicWidth(), arrow.getIntrinsicHeight());
setCompoundDrawablesRelative(null, null, arrow, null);
AppCompat.setTint(arrow, getResources().getColor(R.color.colorMenuText));
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.TextInputSpinner, defStyleAttr, 0);
mEntities = a.getTextArray(R.styleable.TextInputSpinner_android_entries);
a.recycle();
mPopup = new ListPopupWindow(context, attrs, defStyleAttr, R.style.AppTheme_PopupMenu_Overflow);
mPopup.setAdapter(new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item, mEntities));
mPopup.setOnItemClickListener((parent, view, position, id) -> {
setSelection(position);
mPopup.dismiss();
});
mPopup.setAnchorView(this);
mPopup.setVerticalOffset(-ScreenUtils.dpToPx(5));
mPopup.setHorizontalOffset(ScreenUtils.dpToPx(4));
mPopup.setWidth(getResources().getDisplayMetrics().widthPixels - ScreenUtils.dpToPx(16));
mPopup.setModal(true);
setSelection(0);
}
public CircleRangeView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleRangeView);
rangeColorArray = typedArray.getTextArray(R.styleable.CircleRangeView_rangeColorArray);
rangeValueArray = typedArray.getTextArray(R.styleable.CircleRangeView_rangeValueArray);
rangeTextArray = typedArray.getTextArray(R.styleable.CircleRangeView_rangeTextArray);
borderColor = typedArray.getColor(R.styleable.CircleRangeView_borderColor, borderColor);
cursorColor = typedArray.getColor(R.styleable.CircleRangeView_cursorColor, cursorColor);
extraTextColor = typedArray.getColor(R.styleable.CircleRangeView_extraTextColor, extraTextColor);
rangeTextSize = typedArray.getDimensionPixelSize(R.styleable.CircleRangeView_rangeTextSize, rangeTextSize);
extraTextSize = typedArray.getDimensionPixelSize(R.styleable.CircleRangeView_extraTextSize, extraTextSize);
typedArray.recycle();
if (rangeColorArray == null || rangeValueArray == null || rangeTextArray == null) {
throw new IllegalArgumentException("CircleRangeView : rangeColorArray、 rangeValueArray、rangeTextArray must be not null ");
}
if (rangeColorArray.length != rangeValueArray.length
|| rangeColorArray.length != rangeTextArray.length
|| rangeValueArray.length != rangeTextArray.length) {
throw new IllegalArgumentException("arrays must be equal length");
}
this.mSection = rangeColorArray.length;
mSparkleWidth = dp2px(15);
mCalibrationWidth = dp2px(10);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mRectFProgressArc = new RectF();
mRectFCalibrationFArc = new RectF();
mRectText = new Rect();
mBackgroundColor = android.R.color.transparent;
}
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.list_preference, defStyleAttr, defStyleRes);
mEntries = a.getTextArray(R.styleable.list_preference_entry_arr);
a.recycle();
}