Java Code Examples for android.widget.TextView#getTextColors()
The following examples show how to use
android.widget.TextView#getTextColors() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailSharedElementEnterCallback.java From animation-samples with Apache License 2.0 | 6 votes |
@Override public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { TextView author = getAuthor(); targetTextSize = author.getTextSize(); targetTextColors = author.getTextColors(); targetPadding = new Rect(author.getPaddingLeft(), author.getPaddingTop(), author.getPaddingRight(), author.getPaddingBottom()); if (IntentUtil.hasAll(intent, IntentUtil.TEXT_COLOR, IntentUtil.FONT_SIZE, IntentUtil.PADDING)) { author.setTextColor(intent.getIntExtra(IntentUtil.TEXT_COLOR, Color.BLACK)); float textSize = intent.getFloatExtra(IntentUtil.FONT_SIZE, targetTextSize); author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); Rect padding = intent.getParcelableExtra(IntentUtil.PADDING); author.setPadding(padding.left, padding.top, padding.right, padding.bottom); } }
Example 2
Source File: FloorView.java From mapwize-ui-android with MIT License | 6 votes |
private void initialize(@NonNull Context context) { animationView = new View(context); animationView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); GradientDrawable drawable = new GradientDrawable(); drawable.setShape(GradientDrawable.OVAL); drawable.setColor(ContextCompat.getColor(context, io.mapwize.mapwizesdk.R.color.mapwize_main_color)); animationView.setBackground(drawable); animationView.setVisibility(INVISIBLE); this.addView(animationView); textView = new TextView(context); oldTvColors = textView.getTextColors(); textView.setText(floor.getName()); textView.setGravity(Gravity.CENTER); textView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); this.addView(textView); }
Example 3
Source File: RichText.java From AndroidMathKeyboard with Apache License 2.0 | 6 votes |
/** * 设置显示富文本数据的控件 * * @param textView 控件 */ public RichText into(TextView textView, AFCallback callback) { this.textView = textView; if (TextUtils.isEmpty(tag)){ tag = context.getClass().getName(); } RichTextManager.bind(tag,this); if (imgClickable) { this.textView.setMovementMethod(LinkMovementMethod.getInstance()); } HashMap<String, String> hashMap = null; if (isResize) { hashMap = HtmlUtil.getImgWidthHeightByHtmlStr(richText); } if (null != imageGetter) { imageGetter.recycleBitmap(); } try { imageGetter = new AFImageGetter(context,this, textView, hashMap,margin,isDownload,callback); } catch (OutOfMemoryError e) { e.printStackTrace(); } tagHandler = new AFTagHandler(textView.getTextColors(), imgClickListener); textView.setText(Html.fromHtml(richText, imageGetter, tagHandler)); return this; }
Example 4
Source File: DetailSharedElementEnterCallback.java From atlas with Apache License 2.0 | 6 votes |
@Override public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { TextView author = getAuthor(); targetTextSize = author.getTextSize(); targetTextColors = author.getTextColors(); targetPadding = new Rect(author.getPaddingLeft(), author.getPaddingTop(), author.getPaddingRight(), author.getPaddingBottom()); if (IntentUtil.INSTANCE.hasAll(intent, IntentUtil.INSTANCE.getTEXT_COLOR(), IntentUtil.INSTANCE.getFONT_SIZE(), IntentUtil.INSTANCE.getPADDING())) { author.setTextColor(intent.getIntExtra(IntentUtil.INSTANCE.getTEXT_COLOR(), Color.BLACK)); float textSize = intent.getFloatExtra(IntentUtil.INSTANCE.getFONT_SIZE(), targetTextSize); author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); Rect padding = intent.getParcelableExtra(IntentUtil.INSTANCE.getPADDING()); author.setPadding(padding.left, padding.top, padding.right, padding.bottom); } }
Example 5
Source File: DetailSharedElementEnterCallback.java From android-instant-apps with Apache License 2.0 | 6 votes |
@Override public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { TextView author = getAuthor(); targetTextSize = author.getTextSize(); targetTextColors = author.getTextColors(); targetPadding = new Rect(author.getPaddingLeft(), author.getPaddingTop(), author.getPaddingRight(), author.getPaddingBottom()); if (IntentUtil.hasAll(intent, IntentUtil.TEXT_COLOR, IntentUtil.FONT_SIZE, IntentUtil.PADDING)) { author.setTextColor(intent.getIntExtra(IntentUtil.TEXT_COLOR, Color.BLACK)); float textSize = intent.getFloatExtra(IntentUtil.FONT_SIZE, targetTextSize); author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); Rect padding = intent.getParcelableExtra(IntentUtil.PADDING); author.setPadding(padding.left, padding.top, padding.right, padding.bottom); } }
Example 6
Source File: SimpleMonthView.java From SublimePicker with Apache License 2.0 | 6 votes |
/** * Applies the specified text appearance resource to a paint, returning the * text color if one is set in the text appearance. * * @param p the paint to modify * @param resId the resource ID of the text appearance * @return the text color, if available */ private ColorStateList applyTextAppearance(Paint p, int resId) { // Workaround for inaccessible R.styleable.TextAppearance_* TextView tv = new TextView(mContext); if (SUtils.isApi_23_OrHigher()) { tv.setTextAppearance(resId); } else { //noinspection deprecation tv.setTextAppearance(mContext, resId); } p.setTypeface(tv.getTypeface()); p.setTextSize(tv.getTextSize()); final ColorStateList textColor = tv.getTextColors(); if (textColor != null) { final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0); p.setColor(enabledColor); } return textColor; }
Example 7
Source File: BaseAlarmViewHolder.java From ClockPlus with GNU General Public License v3.0 | 5 votes |
private void bindTime(Alarm alarm) { String time = DateFormat.getTimeFormat(getContext()).format(new Date(alarm.ringsAt())); if (DateFormat.is24HourFormat(getContext())) { mTime.setText(time); } else { TimeTextUtils.setText(time, mTime); } // Use a mock TextView to get our colors, because its ColorStateList is never // mutated for the lifetime of this ViewHolder (even when reused). // This solution is robust against dark/light theme changes, whereas using // color resources is not. TextView colorsSource = (TextView) itemView.findViewById(R.id.colors_source); ColorStateList colors = colorsSource.getTextColors(); int def = colors.getDefaultColor(); // Too light // int disabled = colors.getColorForState(new int[] {-android.R.attr.state_enabled}, def); // Material guidelines say text hints and disabled text should have the same color. int disabled = colorsSource.getCurrentHintTextColor(); // However, digging around in the system's textColorHint for 21+ says its 50% black for our // light theme. I'd like to follow what the guidelines says, but I want code that is robust // against theme changes. Alternatively, override the attribute values to what you want // in both your dark and light themes... // int disabled = ContextCompat.getColor(getContext(), R.color.text_color_disabled_light); // We only have two states, so we don't care about losing the other state colors. mTime.setTextColor(alarm.isEnabled() ? def : disabled); }
Example 8
Source File: TextColorPaint.java From NightOwl with Apache License 2.0 | 5 votes |
@Override public Object[] setup(View view, TypedArray a, int attr) { TextView tv = (TextView) view; ColorStateList color1 = tv.getTextColors(); ColorStateList color2 = a.getColorStateList(attr); return new ColorStateList[]{ color1, color2 }; }
Example 9
Source File: TypefaceManager.java From Android-Font-Library with The Unlicense | 5 votes |
public static void onDrawHelper(Canvas canvas, TextView target, DrawCallback drawCallback) { if (target.isInEditMode()) { return; } final ExtraFontData data = getFontData(target, false); if (data == null) { return; } if (data.borderWidth > 0) { final Paint paint = target.getPaint(); // setup stroke final Style oldStyle = paint.getStyle(); final ColorStateList oldTextColors = target.getTextColors(); final float oldStrokeWidth = paint.getStrokeWidth(); target.setTextColor(data.borderColor); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(data.borderWidth); drawCallback.onDrawCall(canvas); target.setTextColor(oldTextColors); paint.setStyle(oldStyle); paint.setStrokeWidth(oldStrokeWidth); } }
Example 10
Source File: PXTextViewStyleAdapter.java From pixate-freestyle-android with Apache License 2.0 | 5 votes |
private Map<int[], Integer> getExistingColorStates(TextView view) { Map<int[], Integer> map = new LinkedHashMap<int[], Integer>(); ColorStateList textColors = view.getTextColors(); if (textColors != null) { try { Field specsField = textColors.getClass().getDeclaredField("mStateSpecs"); specsField.setAccessible(true); int[][] stateSpecs = (int[][]) specsField.get(textColors); Field colorsField = textColors.getClass().getDeclaredField("mColors"); colorsField.setAccessible(true); int[] colors = (int[]) colorsField.get(textColors); // These all should match if (stateSpecs != null && colors != null && stateSpecs.length == colors.length) { // load the map with the existing states for (int i = 0; i < stateSpecs.length; i++) { map.put(stateSpecs[i], colors[i]); } } } catch (Exception e) { PXLog.e(TAG, e, "Error getting the state set"); } finally { } } return map; }
Example 11
Source File: NumberPicker.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private void init() { mSolidColor = 0; mSelectionDivider = new Paint(); mSelectionDivider.setColor(Theme.getColor(Theme.key_dialogButton)); mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics()); mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics()); mMinHeight = SIZE_UNSPECIFIED; mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics()); if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) { throw new IllegalArgumentException("minHeight > maxHeight"); } mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics()); mMaxWidth = SIZE_UNSPECIFIED; if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) { throw new IllegalArgumentException("minWidth > maxWidth"); } mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED); mPressedStateHelper = new PressedStateHelper(); setWillNotDraw(false); mInputText = new TextView(getContext()); mInputText.setGravity(Gravity.CENTER); mInputText.setSingleLine(true); mInputText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); mInputText.setBackgroundResource(0); mInputText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); addView(mInputText, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; mTextSize = (int) mInputText.getTextSize(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(mTextSize); paint.setTypeface(mInputText.getTypeface()); ColorStateList colors = mInputText.getTextColors(); int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE); paint.setColor(color); mSelectorWheelPaint = paint; mFlingScroller = new Scroller(getContext(), null, true); mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f)); updateInputTextView(); }
Example 12
Source File: NumberPicker.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private void init() { mSolidColor = 0; mSelectionDivider = new Paint(); mSelectionDivider.setColor(Theme.getColor(Theme.key_dialogButton)); mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics()); mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics()); mMinHeight = SIZE_UNSPECIFIED; mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics()); if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) { throw new IllegalArgumentException("minHeight > maxHeight"); } mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics()); mMaxWidth = SIZE_UNSPECIFIED; if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) { throw new IllegalArgumentException("minWidth > maxWidth"); } mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED); mPressedStateHelper = new PressedStateHelper(); setWillNotDraw(false); mInputText = new TextView(getContext()); mInputText.setGravity(Gravity.CENTER); mInputText.setSingleLine(true); mInputText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); mInputText.setBackgroundResource(0); mInputText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); addView(mInputText, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; mTextSize = (int) mInputText.getTextSize(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(mTextSize); paint.setTypeface(mInputText.getTypeface()); ColorStateList colors = mInputText.getTextColors(); int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE); paint.setColor(color); mSelectorWheelPaint = paint; mFlingScroller = new Scroller(getContext(), null, true); mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f)); updateInputTextView(); }
Example 13
Source File: ImitateWandoujiaActivity.java From AndroidStudyDemo with GNU General Public License v2.0 | 4 votes |
private void setViewTextAlpha(TextView v ,int alpha){ ColorStateList colorStateList = v.getTextColors(); v.setTextColor(colorStateList.withAlpha(alpha)); }
Example 14
Source File: MainActivity.java From WanDaoJiaIndex with Apache License 2.0 | 4 votes |
private void setViewTextAlpha(TextView v ,int alpha){ ColorStateList colorStateList = v.getTextColors(); v.setTextColor(colorStateList.withAlpha(alpha)); }
Example 15
Source File: NumberPicker.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private void init() { mSolidColor = 0; mSelectionDivider = new Paint(); mSelectionDivider.setColor(Theme.getColor(Theme.key_dialogButton)); mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics()); mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics()); mMinHeight = SIZE_UNSPECIFIED; mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics()); if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) { throw new IllegalArgumentException("minHeight > maxHeight"); } mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics()); mMaxWidth = SIZE_UNSPECIFIED; if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) { throw new IllegalArgumentException("minWidth > maxWidth"); } mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED); mPressedStateHelper = new PressedStateHelper(); setWillNotDraw(false); mInputText = new TextView(getContext()); mInputText.setGravity(Gravity.CENTER); mInputText.setSingleLine(true); mInputText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); mInputText.setBackgroundResource(0); mInputText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); mInputText.setVisibility(INVISIBLE); addView(mInputText, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; mTextSize = (int) mInputText.getTextSize(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(mTextSize); paint.setTypeface(mInputText.getTypeface()); ColorStateList colors = mInputText.getTextColors(); int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE); paint.setColor(color); mSelectorWheelPaint = paint; mFlingScroller = new Scroller(getContext(), null, true); mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f)); updateInputTextView(); }
Example 16
Source File: NumberPicker.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void init() { mSolidColor = 0; mSelectionDivider = new Paint(); mSelectionDivider.setColor(Theme.getColor(Theme.key_dialogButton)); mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics()); mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics()); mMinHeight = SIZE_UNSPECIFIED; mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics()); if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) { throw new IllegalArgumentException("minHeight > maxHeight"); } mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics()); mMaxWidth = SIZE_UNSPECIFIED; if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) { throw new IllegalArgumentException("minWidth > maxWidth"); } mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED); mPressedStateHelper = new PressedStateHelper(); setWillNotDraw(false); mInputText = new TextView(getContext()); mInputText.setGravity(Gravity.CENTER); mInputText.setSingleLine(true); mInputText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); mInputText.setBackgroundResource(0); mInputText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); mInputText.setVisibility(INVISIBLE); addView(mInputText, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ViewConfiguration configuration = ViewConfiguration.get(getContext()); mTouchSlop = configuration.getScaledTouchSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT; mTextSize = (int) mInputText.getTextSize(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(mTextSize); paint.setTypeface(mInputText.getTypeface()); ColorStateList colors = mInputText.getTextColors(); int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE); paint.setColor(color); mSelectorWheelPaint = paint; mFlingScroller = new Scroller(getContext(), null, true); mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f)); updateInputTextView(); }