List of usage examples for android.content.res TypedArray getString
@Nullable public String getString(@StyleableRes int index)
From source file:com.alimuzaffar.lib.pin.PinEntryEditText.java
private void init(Context context, AttributeSet attrs) { float multi = context.getResources().getDisplayMetrics().density; mLineStroke = multi * mLineStroke;//from ww w. j a va 2 s . com mLineStrokeSelected = multi * mLineStrokeSelected; mSpace = multi * mSpace; //convert to pixels for our density mTextBottomPadding = multi * mTextBottomPadding; //convert to pixels for our density TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PinEntryEditText, 0, 0); try { TypedValue outValue = new TypedValue(); ta.getValue(R.styleable.PinEntryEditText_pinAnimationType, outValue); mAnimatedType = outValue.data; mMask = ta.getString(R.styleable.PinEntryEditText_pinCharacterMask); mSingleCharHint = ta.getString(R.styleable.PinEntryEditText_pinRepeatedHint); mLineStroke = ta.getDimension(R.styleable.PinEntryEditText_pinLineStroke, mLineStroke); mLineStrokeSelected = ta.getDimension(R.styleable.PinEntryEditText_pinLineStrokeSelected, mLineStrokeSelected); mSpace = ta.getDimension(R.styleable.PinEntryEditText_pinCharacterSpacing, mSpace); mTextBottomPadding = ta.getDimension(R.styleable.PinEntryEditText_pinTextBottomPadding, mTextBottomPadding); mIsDigitSquare = ta.getBoolean(R.styleable.PinEntryEditText_pinBackgroundIsSquare, mIsDigitSquare); mPinBackground = ta.getDrawable(R.styleable.PinEntryEditText_pinBackgroundDrawable); ColorStateList colors = ta.getColorStateList(R.styleable.PinEntryEditText_pinLineColors); if (colors != null) { mColorStates = colors; } } finally { ta.recycle(); } mCharPaint = new Paint(getPaint()); mLastCharPaint = new Paint(getPaint()); mSingleCharPaint = new Paint(getPaint()); mLinesPaint = new Paint(getPaint()); mLinesPaint.setStrokeWidth(mLineStroke); TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorControlActivated, outValue, true); int colorSelected = outValue.data; mColors[0] = colorSelected; int colorFocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal); mColors[1] = colorFocused; int colorUnfocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal); mColors[2] = colorUnfocused; setBackgroundResource(0); mMaxLength = attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4); mNumChars = mMaxLength; //Disable copy paste super.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); // When tapped, move cursor to end of text. super.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setSelection(getText().length()); if (mClickListener != null) { mClickListener.onClick(v); } } }); super.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { setSelection(getText().length()); return true; } }); //If input type is password and no mask is set, use a default mask if ((getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD && TextUtils.isEmpty(mMask)) { mMask = "\u25CF"; } else if ((getInputType() & InputType.TYPE_NUMBER_VARIATION_PASSWORD) == InputType.TYPE_NUMBER_VARIATION_PASSWORD && TextUtils.isEmpty(mMask)) { mMask = "\u25CF"; } if (!TextUtils.isEmpty(mMask)) { mMaskChars = getMaskChars(); } //Height of the characters, used if there is a background drawable getPaint().getTextBounds("|", 0, 1, mTextHeight); mAnimate = mAnimatedType > -1; }
From source file:com.eutectoid.dosomething.picker.PlacePickerFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_place_picker_fragment); setRadiusInMeters(a.getInt(R.styleable.picker_place_picker_fragment_radius_in_meters, radiusInMeters)); setResultsLimit(a.getInt(R.styleable.picker_place_picker_fragment_results_limit, resultsLimit)); if (a.hasValue(R.styleable.picker_place_picker_fragment_results_limit)) { setSearchText(a.getString(R.styleable.picker_place_picker_fragment_search_text)); }//w w w . j a va 2 s . com showSearchBox = a.getBoolean(R.styleable.picker_place_picker_fragment_show_search_box, showSearchBox); a.recycle(); }
From source file:com.amitupadhyay.aboutexample.ui.widget.CollapsingTitleLayout.java
public CollapsingTitleLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setWillNotDraw(false);//from w w w . ja v a 2 s .c o m paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout); final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; // first check if all insets set the same titleInsetStart = titleInsetEnd = titleInsetBottom = a .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInset, 0); titleInsetTop = titleInsetStart; if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetStart)) { final int insetStart = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetStart, 0); if (isRtl) { titleInsetEnd = insetStart; } else { titleInsetStart = insetStart; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetTop)) { titleInsetTop = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetTop, 0); } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetEnd)) { final int insetEnd = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetEnd, 0); if (isRtl) { titleInsetStart = insetEnd; } else { titleInsetEnd = insetEnd; } } if (a.hasValue(R.styleable.CollapsingTitleLayout_titleInsetBottom)) { titleInsetBottom = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_titleInsetBottom, 0); } final int textAppearance = a.getResourceId(R.styleable.CollapsingTitleLayout_android_textAppearance, android.R.style.TextAppearance); TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.CollapsingTextAppearance); paint.setColor(atp.getColor(R.styleable.CollapsingTextAppearance_android_textColor, Color.WHITE)); collapsedTextSize = atp.getDimensionPixelSize(R.styleable.CollapsingTextAppearance_android_textSize, 0); if (atp.hasValue(R.styleable.CollapsingTextAppearance_font)) { paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.CollapsingTextAppearance_font))); } atp.recycle(); if (a.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) { collapsedTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0); paint.setTextSize(collapsedTextSize); } maxExpandedTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_maxExpandedTextSize, Integer.MAX_VALUE); lineHeightHint = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_lineHeightHint, 0); maxLines = a.getInteger(R.styleable.CollapsingTitleLayout_android_maxLines, 5); a.recycle(); }
From source file:io.plaidapp.ui.widget.CutoutTextView.java
public CutoutTextView(Context context, AttributeSet attrs) { super(context, attrs); textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CutoutTextView, 0, 0); if (a.hasValue(R.styleable.CutoutTextView_android_fontFamily)) { try {/*from w ww . j av a2 s .com*/ Typeface font = ResourcesCompat.getFont(getContext(), a.getResourceId(R.styleable.CutoutTextView_android_fontFamily, 0)); if (font != null) { textPaint.setTypeface(font); } } catch (Resources.NotFoundException nfe) { } } if (a.hasValue(R.styleable.CutoutTextView_foregroundColor)) { foregroundColor = a.getColor(R.styleable.CutoutTextView_foregroundColor, foregroundColor); } if (a.hasValue(R.styleable.CutoutTextView_android_text)) { text = a.getString(R.styleable.CutoutTextView_android_text); } maxTextSize = context.getResources().getDimensionPixelSize(R.dimen.display_4_text_size); a.recycle(); }
From source file:de.mrapp.android.validation.PasswordEditText.java
/** * Obtains the prefix of helper texts, which are shown depending on the password strength, from * a specific typed array.// w ww . ja v a 2 s . com * * @param typedArray * The typed array, the prefix should be obtained from, as an instance of the class * {@link TypedArray}. The typed array may not be null */ private void obtainPasswordVerificationPrefix(@NonNull final TypedArray typedArray) { String format = typedArray.getString(R.styleable.PasswordEditText_passwordVerificationPrefix); if (format == null) { format = getResources().getString(R.string.password_verification_prefix); } setPasswordVerificationPrefix(format); }
From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java
private static PropertyValuesHolder getPVH(TypedArray styledAttributes, int valueType, int valueFromId, int valueToId, String propertyName) { TypedValue tvFrom = styledAttributes.peekValue(valueFromId); boolean hasFrom = (tvFrom != null); int fromType = hasFrom ? tvFrom.type : 0; TypedValue tvTo = styledAttributes.peekValue(valueToId); boolean hasTo = (tvTo != null); int toType = hasTo ? tvTo.type : 0; if (valueType == VALUE_TYPE_UNDEFINED) { // Check whether it's color type. If not, fall back to default type (i.e. float type) if ((hasFrom && isColorType(fromType)) || (hasTo && isColorType(toType))) { valueType = VALUE_TYPE_COLOR; } else {/* w w w. j av a2 s.com*/ valueType = VALUE_TYPE_FLOAT; } } boolean getFloats = (valueType == VALUE_TYPE_FLOAT); PropertyValuesHolder returnValue = null; if (valueType == VALUE_TYPE_PATH) { String fromString = styledAttributes.getString(valueFromId); String toString = styledAttributes.getString(valueToId); PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString); PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString); if (nodesFrom != null || nodesTo != null) { if (nodesFrom != null) { TypeEvaluator evaluator = new PathDataEvaluator(); if (nodesTo != null) { if (!PathParser.canMorph(nodesFrom, nodesTo)) { throw new InflateException(" Can't morph from " + fromString + " to " + toString); } returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, nodesFrom, nodesTo); } else { returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesFrom); } } else if (nodesTo != null) { TypeEvaluator evaluator = new PathDataEvaluator(); returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesTo); } } } else { TypeEvaluator evaluator = null; // Integer and float value types are handled here. if (valueType == VALUE_TYPE_COLOR) { // special case for colors: ignore valueType and get ints evaluator = ArgbEvaluator.getInstance(); } if (getFloats) { float valueFrom; float valueTo; if (hasFrom) { if (fromType == TypedValue.TYPE_DIMENSION) { valueFrom = styledAttributes.getDimension(valueFromId, 0f); } else { valueFrom = styledAttributes.getFloat(valueFromId, 0f); } if (hasTo) { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = styledAttributes.getDimension(valueToId, 0f); } else { valueTo = styledAttributes.getFloat(valueToId, 0f); } returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom, valueTo); } else { returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom); } } else { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = styledAttributes.getDimension(valueToId, 0f); } else { valueTo = styledAttributes.getFloat(valueToId, 0f); } returnValue = PropertyValuesHolder.ofFloat(propertyName, valueTo); } } else { int valueFrom; int valueTo; if (hasFrom) { if (fromType == TypedValue.TYPE_DIMENSION) { valueFrom = (int) styledAttributes.getDimension(valueFromId, 0f); } else if (isColorType(fromType)) { valueFrom = styledAttributes.getColor(valueFromId, 0); } else { valueFrom = styledAttributes.getInt(valueFromId, 0); } if (hasTo) { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = (int) styledAttributes.getDimension(valueToId, 0f); } else if (isColorType(toType)) { valueTo = styledAttributes.getColor(valueToId, 0); } else { valueTo = styledAttributes.getInt(valueToId, 0); } returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom, valueTo); } else { returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom); } } else { if (hasTo) { if (toType == TypedValue.TYPE_DIMENSION) { valueTo = (int) styledAttributes.getDimension(valueToId, 0f); } else if (isColorType(toType)) { valueTo = styledAttributes.getColor(valueToId, 0); } else { valueTo = styledAttributes.getInt(valueToId, 0); } returnValue = PropertyValuesHolder.ofInt(propertyName, valueTo); } } } if (returnValue != null && evaluator != null) { returnValue.setEvaluator(evaluator); } } return returnValue; }
From source file:co.lujun.popmenulayout.PopMenuLayout.java
private void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) { TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PopMenuLayout, defStyleAttr, 0); mConfigJson = attributes.getString(R.styleable.PopMenuLayout_config_json); mLevel2MenuAnimStyle = attributes.getResourceId(R.styleable.PopMenuLayout_level2_menu_anim_style, mLevel2MenuAnimStyle);// w ww .j ava 2s.co m mLevel1MenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_level1_menu_item_height, Util.dp2px(context, mLevel1MenuItemHeight)); mChildMenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_child_menu_item_height, Util.dp2px(context, mChildMenuItemHeight)); isWithLevel1MenuWidth = attributes.getBoolean(R.styleable.PopMenuLayout_cmenu_w_follow_level1_menu, isWithLevel1MenuWidth); mMenuDividerDp = attributes.getDimension(R.styleable.PopMenuLayout_menu_divider_width, Util.dp2px(context, mMenuDividerDp)); mMenuTextPaddingLeft = attributes.getDimension(R.styleable.PopMenuLayout_menu_left_padding, Util.dp2px(context, mMenuTextPaddingLeft)); mMenuTextPaddingRight = attributes.getDimension(R.styleable.PopMenuLayout_menu_right_padding, Util.dp2px(context, mMenuTextPaddingRight)); mMenuTextPaddingTop = attributes.getDimension(R.styleable.PopMenuLayout_menu_top_padding, Util.dp2px(context, mMenuTextPaddingTop)); mMenuTextPaddingBottom = attributes.getDimension(R.styleable.PopMenuLayout_menu_bottom_padding, Util.dp2px(context, mMenuTextPaddingBottom)); mDividerColor = attributes.getColor(R.styleable.PopMenuLayout_menu_divider_color, mDividerColor); mExpandableIcon = attributes.getResourceId(R.styleable.PopMenuLayout_menu_expandable_icon, mExpandableIcon); mMenuTextColor = attributes.getColor(R.styleable.PopMenuLayout_menu_text_color, mMenuTextColor); mHorizontalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_horizontal_menu_bg, mHorizontalMenuBackgroundRes); mVerticalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_vertical_menu_bg, mVerticalMenuBackgroundRes); mMenuTextSize = attributes.getDimension(R.styleable.PopMenuLayout_menu_text_size, Util.sp2px(context, mMenuTextSize)); mMaxMenuItemCount = attributes.getInteger(R.styleable.PopMenuLayout_child_menu_max_count, mMaxMenuItemCount); mLevel1MenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_level1_menu_layout_bg_color, mLevel1MenuLayoutBgColor); mChildMenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_cmenu_layout_bg_color, mChildMenuLayoutBgColor); mDividerMarginLeft = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_left, Util.dp2px(context, mDividerMarginLeft)); mDividerMarginRight = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_right, Util.dp2px(context, mDividerMarginRight)); mDividerMarginTop = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_top, Util.dp2px(context, mDividerMarginTop)); mDividerMarginBottom = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_bottom, Util.dp2px(context, mDividerMarginBottom)); attributes.recycle(); }
From source file:com.wlanjie.streaming.camera.CameraView.java
@SuppressWarnings("WrongConstant") public CameraView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // Internal setup final View view = View.inflate(context, R.layout.texture_view, this); mGLSurfaceView = (GLSurfaceView) view.findViewById(R.id.gl_surface_view); mGLSurfaceView.setEGLContextClientVersion(2); mGLSurfaceView.setRenderer(this); mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); mTextureId = OpenGLUtils.getExternalOESTextureID(); mSurfaceTexture = new SurfaceTexture(mTextureId); mCallbacks = new CallbackBridge(); if (Build.VERSION.SDK_INT < 21) { mImpl = new Camera1(mCallbacks); } else if (Build.VERSION.SDK_INT < 23) { mImpl = new Camera2(mCallbacks, context); } else {//from w w w. j a va2 s . c o m mImpl = new Camera2Api23(mCallbacks, context); } mImpl.setPreviewSurface(mSurfaceTexture); // Attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CameraView, defStyleAttr, R.style.Widget_CameraView); mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, false); setFacing(a.getInt(R.styleable.CameraView_facing, FACING_BACK)); String aspectRatio = a.getString(R.styleable.CameraView_aspectRatio); if (aspectRatio != null) { setAspectRatio(AspectRatio.parse(aspectRatio)); } else { setAspectRatio(Constants.DEFAULT_ASPECT_RATIO); } setFlash(a.getInt(R.styleable.CameraView_flash, Constants.FLASH_AUTO)); a.recycle(); // Display orientation detector mDisplayOrientationDetector = new DisplayOrientationDetector(context) { @Override public void onDisplayOrientationChanged(int displayOrientation) { mImpl.setDisplayOrientation(displayOrientation); } }; }
From source file:net.hadifar.dope.ui.widget.pagerIndicator.NumericPageIndicator.java
@SuppressWarnings("deprecation") public NumericPageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) { return;// ww w .ja v a2s . co m } // Load defaults from resources final Resources res = getResources(); final int defaultTextColor = res.getColor(R.color.default_page_number_indicator_text_color); final int defaultPageNumberTextColor = res .getColor(R.color.default_page_number_indicator_page_number_text_color); final boolean defaultPageNumberTextBold = res .getBoolean(R.bool.default_page_number_indicator_page_number_text_bold); final int defaultButtonPressedColor = res .getColor(R.color.default_page_number_indicator_pressed_button_color); final float defaultTopPadding = res.getDimension(R.dimen.default_page_number_indicator_top_padding); final float defaultBottomPadding = res.getDimension(R.dimen.default_page_number_indicator_bottom_padding); final float defaultTextSize = res.getDimension(R.dimen.default_page_number_indicator_text_size); final boolean defaultShowChangePageButtons = res .getBoolean(R.bool.default_page_number_indicator_show_change_page_buttons); final boolean defaultShowStartEndButtons = res .getBoolean(R.bool.default_page_number_indicator_show_start_end_buttons); // Retrieve styles attributes final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumericPageIndicator, defStyle, 0); mTextTemplate = a.getString(R.styleable.NumericPageIndicator_textTemplate); if (mTextTemplate == null) { mTextTemplate = res.getString(R.string.default_page_number_indicator_text_template); } parseTextTemplate(); mTextPreviousButton = a.getString(R.styleable.NumericPageIndicator_previousButtonText); if (mTextPreviousButton == null) { mTextPreviousButton = res.getString(R.string.default_page_number_indicator_previous_button_text); } mTextNextButton = a.getString(R.styleable.NumericPageIndicator_nextButtonText); if (mTextNextButton == null) { mTextNextButton = res.getString(R.string.default_page_number_indicator_next_button_text); } mColorText = a.getColor(R.styleable.NumericPageIndicator_android_textColor, defaultTextColor); mColorPageNumberText = a.getColor(R.styleable.NumericPageIndicator_pageNumberTextColor, defaultPageNumberTextColor); mPageNumberTextBold = a.getBoolean(R.styleable.NumericPageIndicator_pageNumberTextBold, defaultPageNumberTextBold); mColorPressedButton = a.getColor(R.styleable.NumericPageIndicator_pressedButtonColor, defaultButtonPressedColor); mPaddingTop = a.getDimension(R.styleable.NumericPageIndicator_android_paddingTop, defaultTopPadding); mPaddingBottom = a.getDimension(R.styleable.NumericPageIndicator_android_paddingBottom, defaultBottomPadding); mPaintText.setColor(mColorText); mShowChangePageButtons = a.getBoolean(R.styleable.NumericPageIndicator_showChangePageButtons, defaultShowChangePageButtons); mShowStartEndButtons = a.getBoolean(R.styleable.NumericPageIndicator_showStartEndButtons, defaultShowStartEndButtons); mPaintButtonBackground.setColor(mColorPressedButton); final float textSize = a.getDimension(R.styleable.NumericPageIndicator_android_textSize, defaultTextSize); mPaintText.setTextSize(textSize); mPaintText.setAntiAlias(true); mPaintPageNumberText.setColor(mColorPageNumberText); mPaintPageNumberText.setTextSize(textSize); mPaintPageNumberText.setAntiAlias(true); if (mPageNumberTextBold) { mPaintPageNumberText.setTypeface(Typeface.DEFAULT_BOLD); } final Drawable background = a.getDrawable(R.styleable.NumericPageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); }
From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java
/** * ?// w w w . j av a 2s .c o m * @param attrs */ private void init(AttributeSet attrs) { mCollapsedStatus = new SparseBooleanArray(); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView); mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines, MAX_COLLAPSED_LINES); mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION); mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable); mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable); textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse); textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand); showExpandCollapseDrawable = typedArray .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true); if (showExpandCollapseDrawable) { if (mExpandDrawable == null) { mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down); } if (mCollapseDrawable == null) { mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up); } } if (TextUtils.isEmpty(textCollapse)) { textCollapse = getContext().getString(R.string.shink); } if (TextUtils.isEmpty(textExpand)) { textExpand = getContext().getString(R.string.expand); } contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor, ContextCompat.getColor(getContext(), R.color.light_gray)); contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize, DisplayUtil.sp2px(14)); collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor, ContextCompat.getColor(getContext(), R.color.main_color)); collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize, DisplayUtil.sp2px(14)); grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT); typedArray.recycle(); // enforces vertical orientation setOrientation(LinearLayout.VERTICAL); // default visibility is gone setVisibility(GONE); }