Example usage for android.widget TextView setTextColor

List of usage examples for android.widget TextView setTextColor

Introduction

In this page you can find the example usage for android.widget TextView setTextColor.

Prototype

@android.view.RemotableViewMethod
public void setTextColor(ColorStateList colors) 

Source Link

Document

Sets the text color.

Usage

From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesView.java

private static void setupAlphabetKey(final TextView alphabetKey, final String label,
        final KeyDrawParams params) {
    alphabetKey.setText(label);/*from   w  w w .ja  va 2s  .  c  o m*/
    alphabetKey.setTextColor(params.mFunctionalTextColor);
    alphabetKey.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mLabelSize);
    alphabetKey.setTypeface(params.mTypeface);
}

From source file:com.andrewshu.android.reddit.common.Common.java

public static void setTextColorFromTheme(int theme, Resources resources, TextView... textViews) {
    int color;/*w  ww  .java2s.c  om*/
    if (Util.isLightTheme(theme))
        color = resources.getColor(R.color.reddit_light_dialog_text_color);
    else
        color = resources.getColor(R.color.reddit_dark_dialog_text_color);
    for (TextView textView : textViews)
        textView.setTextColor(color);
}

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final TextView textView, int color, boolean fromCache) {
    if (fromCache) {
        textView.setTextColor(color);
    } else {//w  w w.  j a  v a  2s.co  m
        Integer colorFrom = textView.getCurrentTextColor();
        Integer colorTo = color;
        ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                textView.setTextColor((Integer) animator.getAnimatedValue());
            }
        });
        colorAnimation.start();
    }
}

From source file:Main.java

public static void traverseAndRecolor(View root, int color, boolean withStates,
        boolean setClickableItemBackgrounds) {
    Context context = root.getContext();

    if (setClickableItemBackgrounds && root.isClickable()) {
        StateListDrawable selectableItemBackground = new StateListDrawable();
        selectableItemBackground.addState(new int[] { android.R.attr.state_pressed },
                new ColorDrawable((color & 0xffffff) | 0x33000000));
        selectableItemBackground.addState(new int[] { android.R.attr.state_focused },
                new ColorDrawable((color & 0xffffff) | 0x44000000));
        selectableItemBackground.addState(new int[] {}, null);
        root.setBackground(selectableItemBackground);
    }/*from  w ww .j  a  v a  2 s.  co m*/

    if (root instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) root;
        for (int i = 0; i < parent.getChildCount(); i++) {
            traverseAndRecolor(parent.getChildAt(i), color, withStates, setClickableItemBackgrounds);
        }

    } else if (root instanceof ImageView) {
        ImageView imageView = (ImageView) root;
        Drawable sourceDrawable = imageView.getDrawable();
        if (withStates && sourceDrawable != null && sourceDrawable instanceof BitmapDrawable) {
            imageView.setImageDrawable(
                    makeRecoloredDrawable(context, (BitmapDrawable) sourceDrawable, color, true));
        } else {
            imageView.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }

    } else if (root instanceof TextView) {
        TextView textView = (TextView) root;
        if (withStates) {
            int sourceColor = textView.getCurrentTextColor();
            ColorStateList colorStateList = new ColorStateList(
                    new int[][] { new int[] { android.R.attr.state_pressed },
                            new int[] { android.R.attr.state_focused }, new int[] {} },
                    new int[] { sourceColor, sourceColor, color });
            textView.setTextColor(colorStateList);
        } else {
            textView.setTextColor(color);
        }

    } else if (root instanceof AnalogClock) {
        AnalogClock analogClock = (AnalogClock) root;
        try {
            Field hourHandField = AnalogClock.class.getDeclaredField("mHourHand");
            hourHandField.setAccessible(true);
            Field minuteHandField = AnalogClock.class.getDeclaredField("mMinuteHand");
            minuteHandField.setAccessible(true);
            Field dialField = AnalogClock.class.getDeclaredField("mDial");
            dialField.setAccessible(true);
            BitmapDrawable hourHand = (BitmapDrawable) hourHandField.get(analogClock);
            if (hourHand != null) {
                Drawable d = makeRecoloredDrawable(context, hourHand, color, withStates);
                d.setCallback(analogClock);
                hourHandField.set(analogClock, d);
            }
            BitmapDrawable minuteHand = (BitmapDrawable) minuteHandField.get(analogClock);
            if (minuteHand != null) {
                Drawable d = makeRecoloredDrawable(context, minuteHand, color, withStates);
                d.setCallback(analogClock);
                minuteHandField.set(analogClock, d);
            }
            BitmapDrawable dial = (BitmapDrawable) dialField.get(analogClock);
            if (dial != null) {
                Drawable d = makeRecoloredDrawable(context, dial, color, withStates);
                d.setCallback(analogClock);
                dialField.set(analogClock, d);
            }
        } catch (NoSuchFieldException ignored) {
        } catch (IllegalAccessException ignored) {
        } catch (ClassCastException ignored) {
        } // TODO: catch all exceptions?
    }
}

From source file:ca.rmen.android.scrumchatter.chart.ChartUtils.java

static void addLegendEntry(Context context, ViewGroup legendView, String name, int color) {
    TextView memberLegendEntry = new TextView(context);
    memberLegendEntry.setText(name);/*from w ww  .  j  a va  2  s . c  om*/
    memberLegendEntry.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    memberLegendEntry.setPadding(0, 0,
            context.getResources().getDimensionPixelSize(R.dimen.chart_legend_entry_padding), 0);

    final Drawable icon;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square);
        memberLegendEntry.setTextColor(color);
    } else {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square).mutate();
        DrawableCompat.setTint(icon, color);
    }
    memberLegendEntry.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    legendView.addView(memberLegendEntry);
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Alert animation in//from ww  w  . j a  va  2  s  .  c o  m
 * @param configuration describes all device configuration information
 * @param alertView     View Resources to animate
 * @param textView      alert message to be viewed
 * @param mainView      ViewGroup resources
 * @param text          message to be displayed
 */
private static void animIn(final Configuration configuration, final View alertView, TextView textView,
        final ViewGroup mainView, String text) {
    // Colors
    textView.setTextColor(configuration.getColorTextResId());
    alertView.setBackgroundColor(configuration.getColorBackgroundResId());

    // Content Description
    alertView.setContentDescription(configuration.getMessageType());

    // Setting the text
    textView.setText(text);

    // Animation In
    if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
        animViews(alertView, mainView, configuration, 0, configuration.getHeight(), true);
    } else {
        animViews(alertView, mainView, configuration, mainView.getHeight() - configuration.getHeight(),
                -configuration.getHeight(), true);
    }

    // Delayed animation out
    if (configuration.isCloseable()) {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                animOut(configuration, mainView, alertView);
            }
        }, configuration.getDuration());
    }
}

From source file:com.afeng.xf.widget.snackbarlight.Light.java

/**
 * Make a customized {@link Snackbar} to display a message without any action.
 *
 * @param view The view to find a parent from.
 * @param text The message to display. Formatted text is supported.
 * @param textIcon The left icon of the message.
 * @param backgroundColor The background color of the Snackbar. It should be a resolved color.
 * @param textColor The color of message text.
 * @param duration How long to show the message.
 *                 Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}.
 *
 * @return The customized Snackbar that will be displayed.
 *///from w ww.  j a v a 2  s  .co  m
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, Drawable textIcon,
        @ColorInt int backgroundColor, @ColorInt int textColor, int duration) {
    // Get a usual Snackbar
    Snackbar snackbar = Snackbar.make(view, text, duration);

    // Get the view of it.
    View mView = snackbar.getView();
    // Change the background color.
    mView.setBackgroundColor(backgroundColor);

    // Get the TextView of message.
    TextView textView = (TextView) mView.findViewById(android.support.design.R.id.snackbar_text);
    // Set the left icon of message.
    textView.setCompoundDrawablesWithIntrinsicBounds(textIcon, null, null, null);
    // Set the padding between message and icon.
    textView.setCompoundDrawablePadding(16);
    // To make icon and message aligned.
    textView.setGravity(Gravity.CENTER);
    // Change color of message text.
    textView.setTextColor(textColor);

    return snackbar;
}

From source file:info.papdt.blacklight.support.Utility.java

public static void initDarkTabHost(Activity activity, TabHost tabhost) {
    if (isDarkMode(activity)) {
        int textColor = 0;

        try {//from  ww w . j  a  va 2s.  co  m
            TypedArray array = activity.getTheme().obtainStyledAttributes(R.styleable.BlackLight);
            textColor = array.getColor(R.styleable.BlackLight_CardForeground, 0);
            array.recycle();
        } catch (NotFoundException e) {
            return;
        }

        for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {
            TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
            tv.setTextColor(textColor);
        }
    }
}

From source file:com.android.argb.edhlc.Utils.java

public static void collapse(Context context, final CardView card, TextView title, ImageView selector,
        int minHeight, int maxHeight) {
    title.setTextColor(ContextCompat.getColor(context, R.color.secondary_text));

    Animation rotation = AnimationUtils.loadAnimation(context, R.anim.rotate_180_clockwise);
    selector.startAnimation(rotation);//from  w  w  w.j a v a2  s. c  om
    selector.setColorFilter(ContextCompat.getColor(context, R.color.secondary_text));

    ValueAnimator anim = ValueAnimator.ofInt(maxHeight, minHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
            layoutParams.height = val;
            card.setLayoutParams(layoutParams);
        }
    });
    anim.start();
}

From source file:com.android.argb.edhlc.Utils.java

public static void expand(Context context, final CardView card, TextView title, ImageView selector,
        int minHeight, int maxHeight) {
    title.setTextColor(ContextCompat.getColor(context, R.color.accent_color_dark));

    Animation rotation = AnimationUtils.loadAnimation(context, R.anim.rotate_180_anticlockwise);
    selector.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.arrow_up));
    selector.setRotation(0);//from w ww  .j  a v a 2  s. c o  m
    selector.startAnimation(rotation);
    selector.setColorFilter(ContextCompat.getColor(context, R.color.accent_color_dark));

    ValueAnimator anim = ValueAnimator.ofInt(minHeight, maxHeight);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = card.getLayoutParams();
            layoutParams.height = val;
            card.setLayoutParams(layoutParams);
            Utils.makeViewVisible(card);
        }
    });
    anim.start();
}