下面列出了android.widget.TextView#getTextColors ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
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);
}
/**
* 设置显示富文本数据的控件
*
* @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;
}
@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);
}
}
@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);
}
}
/**
* 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;
}
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);
}
@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 };
}
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);
}
}
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;
}
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();
}
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();
}
private void setViewTextAlpha(TextView v ,int alpha){
ColorStateList colorStateList = v.getTextColors();
v.setTextColor(colorStateList.withAlpha(alpha));
}
private void setViewTextAlpha(TextView v ,int alpha){
ColorStateList colorStateList = v.getTextColors();
v.setTextColor(colorStateList.withAlpha(alpha));
}
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();
}
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();
}