set Text Color for TextView - Android User Interface

Android examples for User Interface:TextView Color

Description

set Text Color for TextView

Demo Code


//package com.java2s;
import android.app.Activity;

import android.support.annotation.ColorRes;

import android.support.annotation.IdRes;

import android.view.View;

import android.widget.TextView;

public class Main {
    public static void setTextColor(@ColorRes int colorRes,
            Activity activity, @IdRes int viewId) {
        TextView view = findView(activity, viewId);
        view.setTextColor(activity.getResources().getColor(colorRes));
    }//from   ww w  .  j  a  va 2  s.c  om

    public static <T extends View> T findView(View parent, @IdRes int viewId) {
        return (T) parent.findViewById(viewId);
    }

    public static <T extends View> T findView(Activity activity,
            @IdRes int viewId) {
        return (T) activity.findViewById(viewId);
    }
}

Related Tutorials