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:android.improving.utils.views.PagerSlidingTabStrip.java

/**
 *  text animation/* www.jav a2  s.  com*/
 * @param view
 * @param color1
 * @param color2
 */
private void animTextColor(TextView view, int color1, int color2) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        view.setTextColor(color2);
    } else {
        if (color1 == color2) {
            view.setTextColor(color2);
        } else {
            ObjectAnimator backgroundColorAnimator = ObjectAnimator.ofObject(view, CHANGECOLORSTRING,
                    new ArgbEvaluator(), color1, color2);
            backgroundColorAnimator.setDuration(100);
            backgroundColorAnimator.start();
        }
    }

}

From source file:cn.bingoogol.tabhost.ui.view.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        v.setBackgroundResource(tabBackgroundResId);
        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);
            // setAllCaps() is only available from API 14, so the upper case is made
            // manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }/* w  w  w  . ja  v  a2  s  . com*/
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
            }
        }
    }

}

From source file:com.anjalimacwan.adapter.NoteListDateAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get the data item for this position
    NoteListItem item = getItem(position);
    String note = item.getNote();
    String date = item.getDate();

    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null)
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_layout_date, parent, false);

    // Lookup view for data population
    TextView noteTitle = (TextView) convertView.findViewById(R.id.noteTitle);
    TextView noteDate = (TextView) convertView.findViewById(R.id.noteDate);

    // Populate the data into the template view using the data object
    noteTitle.setText(note);//from  w w  w.  j  ava 2 s.  c o  m
    noteDate.setText(date);

    // Apply theme
    SharedPreferences pref = getContext().getSharedPreferences(getContext().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    String theme = pref.getString("theme", "light-sans");

    if (theme.contains("light")) {
        noteTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_primary));
        noteDate.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_secondary));
    }

    if (theme.contains("dark")) {
        noteTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_primary_dark));
        noteDate.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_secondary_dark));
    }

    if (theme.contains("sans")) {
        noteTitle.setTypeface(Typeface.SANS_SERIF);
        noteDate.setTypeface(Typeface.SANS_SERIF);
    }

    if (theme.contains("serif")) {
        noteTitle.setTypeface(Typeface.SERIF);
        noteDate.setTypeface(Typeface.SERIF);
    }

    if (theme.contains("monospace")) {
        noteTitle.setTypeface(Typeface.MONOSPACE);
        noteDate.setTypeface(Typeface.MONOSPACE);
    }

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        noteTitle.setTextSize(12);
        noteDate.setTextSize(8);
        break;
    case "small":
        noteTitle.setTextSize(14);
        noteDate.setTextSize(10);
        break;
    case "normal":
        noteTitle.setTextSize(16);
        noteDate.setTextSize(12);
        break;
    case "large":
        noteTitle.setTextSize(18);
        noteDate.setTextSize(14);
        break;
    case "largest":
        noteTitle.setTextSize(20);
        noteDate.setTextSize(16);
        break;
    }

    // Return the completed view to render on screen
    return convertView;
}

From source file:com.abcs.huaqiaobang.tljr.news.tabs.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(tabTextSize);
            //tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//from ww w .  j  a v a2 s.com
            }
        }
    }

}

From source file:net.bible.android.view.util.widget.BookmarkStyleAdapterHelper.java

public void styleView(TextView view, BookmarkStyle bookmarkStyle, Context context, boolean overrideText,
        boolean centreText) {

    // prepare text to be shown
    String baseText;/*w  w  w.j  av  a  2 s  .c o  m*/
    if (overrideText) {
        baseText = sampleText;
    } else {
        baseText = view.getText().toString();
        // avoid multiple *'s
        if (baseText.startsWith("*")) {
            StringUtils.strip(baseText, "*");
        }
    }

    int backgroundColor = Color.WHITE;
    switch (bookmarkStyle) {
    case YELLOW_STAR:
        backgroundColor = UiUtils.getThemeBackgroundColour(context);
        view.setTextColor(UiUtils.getThemeTextColour(context));
        CharSequence imgText = addImageAtStart("* " + baseText, R.drawable.goldstar16x16, context);
        view.setText(imgText, TextView.BufferType.SPANNABLE);
        break;
    case RED_HIGHLIGHT:
        backgroundColor = BookmarkStyle.RED_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    case YELLOW_HIGHLIGHT:
        backgroundColor = BookmarkStyle.YELLOW_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    case GREEN_HIGHLIGHT:
        backgroundColor = BookmarkStyle.GREEN_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    case BLUE_HIGHLIGHT:
        backgroundColor = BookmarkStyle.BLUE_HIGHLIGHT.getBackgroundColor();
        view.setText(baseText);
        break;
    }
    view.setBackgroundColor(backgroundColor);
    view.setHeight(CommonUtils.convertDipsToPx(30));
    if (centreText) {
        view.setGravity(Gravity.CENTER);
    }
}

From source file:com.abct.tljr.news.widget.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(tabTextSize);
            // tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case
            // is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//  ww  w .j a va 2 s  . c  o  m
            }
        }
    }

}

From source file:com.app.sample.chatting.widget.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case
            // is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }/*from   w  w  w.  j av  a  2 s .c  o  m*/
            }
        }
    }

}

From source file:com.adamkruger.myipaddressinfo.IPAddressInfoFragment.java

private void updateViewState() {
    View view = getView();/*from  w ww.j a va 2  s  .c om*/
    if (view != null) {
        ((TextView) view.findViewById(R.id.ipValue)).setText(mIPAddress);
        ((TextView) view.findViewById(R.id.ispValue)).setText(mISP);
        ((TextView) view.findViewById(R.id.countryValue)).setText(mCountry);
        ((TextView) view.findViewById(R.id.cityValue)).setText(mCity);
        ((TextView) view.findViewById(R.id.regionValue)).setText(mRegion);
        ((TextView) view.findViewById(R.id.coordinatesValue)).setText(mLatLong.length() == 0 ? ""
                : Html.fromHtml(
                        String.format("<a href=\"%s\">%s</a>", mapLink(mLatLong, mIPAddress), mLatLong)));

        if (mLastUpdateTime != null) {
            TextView lastUpdateStatus = (TextView) view.findViewById(R.id.lastUpdateStatus);
            if (mLastUpdateTimedOut) {
                lastUpdateStatus
                        .setText(String.format(getResources().getString(R.string.last_update_status_timeout),
                                mLastUpdateElapsedTimeMs / 1000));
                lastUpdateStatus.setTextColor(getResources().getColor(R.color.error_color));
            } else if (mLastUpdateSucceeded) {
                lastUpdateStatus
                        .setText(String.format(getResources().getString(R.string.last_update_status_success),
                                mLastUpdateElapsedTimeMs));
                if (mLastUpdateElapsedTimeMs < 2000) {
                    lastUpdateStatus.setTextColor(getResources().getColor(R.color.success_color));
                } else {
                    lastUpdateStatus.setTextColor(getResources().getColor(R.color.warning_color));
                }
            } else {
                lastUpdateStatus.setText(String.format(
                        getResources().getString(R.string.last_update_status_fail), mLastUpdateElapsedTimeMs));
                lastUpdateStatus.setTextColor(getResources().getColor(R.color.error_color));
            }

            TextView lastUpdateTime = (TextView) view.findViewById(R.id.lastUpdateTime);
            lastUpdateTime.setText(
                    String.format(getResources().getString(R.string.last_update_time), mLastUpdateTime));
            String currentTime = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault())
                    .format(new Date());
            if (currentTime.equals(mLastUpdateTime)) {
                lastUpdateTime.setTextColor(mDefaultLastUpdateTimeColor);
            } else {
                lastUpdateTime.setTextColor(getResources().getColor(R.color.warning_color));
            }
        }
    }
}

From source file:app.lib.beta.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//from ww w.  j a va 2 s . c o m
            }
        }
    }

}

From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private TextView makeTextView(String value, int color, int horizontalPadding) {
    Context context = getActivity();
    TextView textView = new TextView(context);
    textView.setText(value);/*w w w.  ja v a 2s .c o  m*/
    textView.setLayoutParams(
            new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
    textView.setTextAppearance(context, android.R.attr.textAppearanceSmall);
    textView.setTextColor(color);
    textView.setPadding(horizontalPadding, 0, horizontalPadding, 0);
    textView.setSingleLine(false);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        textView.setTextIsSelectable(true);
    }
    return textView;
}