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.brianwu.view.SlidingTabLayout.java

private void scrollToTab(int tabIndex, int positionOffset) {
    final int tabStripChildCount = mTabStrip.getChildCount();
    if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
        return;//from ww w . j  a  v a  2 s .  co  m
    }

    View selectedChild = mTabStrip.getChildAt(tabIndex);

    for (int i = 0; i < mTabStrip.getChildCount(); i++) {
        TextView txtChild = (TextView) mTabStrip.getChildAt(i);
        if (i == tabIndex) {
            txtChild.setTextColor(Color.WHITE);
        } else {
            txtChild.setTextColor(getResources().getColor(R.color.txt_gray_white));
        }
    }

    if (selectedChild != null) {
        int targetScrollX = selectedChild.getLeft() + positionOffset;

        if (tabIndex > 0 || positionOffset > 0) {
            // If we're not at the first child and are mid-scroll, make sure we obey the offset
            targetScrollX -= mTitleOffset;
        }

        scrollTo(targetScrollX, 0);
    }
}

From source file:com.dedipower.portal.android.CDNLanding.java

public void UpdateErrorMessage(String MessageText) {
    TextView ErrorMessage = (TextView) findViewById(R.id.ErrorMessageText);
    if (MessageText.length() == 0) {
        ErrorMessage.setHeight(0);//from   ww  w .  ja v a 2s  . co m
    } else {
        ErrorMessage.setHeight(24);
        ErrorMessage.setTextColor(-65536);
        ErrorMessage.setText(MessageText);
    }
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE TITLE ROW//from  ww  w .  java2  s .  c  o m
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleTitleRow(Map<String, String> att, LinearLayout linear) {
    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setMinimumHeight(30);
    container_layout
            .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue));
    container_layout.setVerticalGravity(Gravity.CENTER);
    container_layout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText("");
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value1"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t1, ltext1);

    LinearLayout.LayoutParams ltext2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t2 = new TextView(context);
    t2.setText(att.get("value2"));
    t2.setTextSize(11);
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t2, ltext2);

    linear.addView(container_layout);
    return linear;
}

From source file:augsburg.se.alltagsguide.event.EventActivity.java

@Override
protected void setMorePageDetails(EventPage page) {
    int color = mPrefUtilities.getCurrentColor();
    if (mPage.getEvent().isAllDay()) {
        fromDateTextView.setText(allDayDateFormat.format(mPage.getEvent().getStartTime()));
        timeToLayout.setVisibility(View.GONE);
    } else {/*  w w w  . ja va  2s.  c o  m*/
        fromDateTextView.setText(dateFormatFrom.format(mPage.getEvent().getStartTime()));
        toDateTextView.setText(dateFormatFrom.format(mPage.getEvent().getEndTime()));
    }

    if (mPage.getAuthor() != null) {
        String authorText = mPage.getAuthor().toText();
        if (!Objects.isNullOrEmpty(authorText)) {
            authorTextView.setText(authorText);
        } else {
            authorLayout.setVisibility(View.GONE);
        }
    } else {
        authorLayout.setVisibility(View.GONE);
    }

    if (!mPage.getCategories().isEmpty()) {
        for (EventCategory category : mPage.getCategories()) {
            @SuppressLint("InflateParams")
            TextView view = (TextView) LayoutInflater.from(this).inflate(R.layout.category_item,
                    categoriesLayout, false);
            view.setText(category.getName());
            view.setTextColor(color);
            view.setBackgroundColor(ContextCompat.getColor(this, android.R.color.white));
            categoriesLayout.addView(view);
        }
    } else {
        categoriesBaseLayout.setVisibility(View.GONE);
    }

    if (!mPage.getTags().isEmpty()) {
        for (EventTag tag : mPage.getTags()) {
            @SuppressLint("InflateParams")
            TextView view = (TextView) LayoutInflater.from(this).inflate(R.layout.tag_item, tagsLayout, false);
            view.setText(tag.getName());
            view.setTextColor(ContextCompat.getColor(this, android.R.color.white));
            view.setBackgroundColor(color);
            tagsLayout.addView(view);
        }
    } else {
        tagsLayout.setVisibility(View.GONE);
    }

    if (mPage.getLocation() != null) {
        String location = "";
        String name = mPage.getLocation().getName();
        String address = mPage.getLocation().getAddress();
        if (name != null) {
            location += name + " - ";
        }
        if (address != null) {
            location += address;
        }
        locationTextView.setText(location);
    }
}

From source file:com.ibuildapp.romanblack.CouponPlugin.CouponAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    try {//ErrorLogging 

        View row;//from   w  ww  .j  a v  a 2  s  .  c  o m

        if (null == convertView) {
        } else {
            row = convertView;
        }

        if (items.get(position).hasImage()) {
            row = layoutInflater.inflate(R.layout.romanblack_coupon_feed_item_image, null);
            ImageView imageView = (ImageView) row.findViewById(R.id.romanblack_coupon_image);
            imageView.setImageResource(R.drawable.romanblack_coupon_no_image);
        } else {
            row = layoutInflater.inflate(R.layout.romanblack_coupon_feed_item, null);
        }

        // change arrow color depending of background color
        ImageView arrow = (ImageView) row.findViewById(R.id.romanblack_coupon_feed_item_arrow);
        if (Utils.isChemeDark(Statics.color1)) {
            arrow.setImageResource(R.drawable.romanblack_coupon_arrow_light);
        } else {
            arrow.setImageResource(R.drawable.romanblack_coupon_arrow);
        }

        TextView title = (TextView) row.findViewById(R.id.romanblack_coupon_title);
        title.setTextColor(Statics.color3);

        TextView description = (TextView) row.findViewById(R.id.romanblack_coupon_description);
        description.setTextColor(Statics.color4);

        title.setText(items.get(position).getTitle());
        description.setText(items.get(position).getAnounce(75));

        if (items.get(position).hasImage()) {
            ImageView imageView = (ImageView) row.findViewById(R.id.romanblack_coupon_image);
            if (imageView != null) {
                if (items.get(position).getImagePath().length() > 0) {
                    Bitmap bitmap = null;
                    Integer key = new Integer(position);
                    if (bitmaps.containsValue(key)) {
                        bitmap = bitmaps.get(key);
                    } else {
                        try {
                            bitmap = decodeImageFile(items.get(position).getImagePath());
                            bitmaps.put(key, bitmap);
                        } catch (Exception e) {
                            Log.w("NEWS ADAPTER", e);
                        }
                    }

                    if (bitmap != null) {
                        imageView.setImageBitmap(bitmap);
                    }
                }
            }
        }
        return row;

    } catch (Exception e) {
        return null;
    }
}

From source file:com.bt.heliniumstudentapp.UpdateClass.java

@Override
protected void onPostExecute(String html) {
    if (html != null) {
        try {// w  w  w .  ja  v a2  s .com
            final JSONObject json = (JSONObject) new JSONTokener(html).nextValue();

            versionName = json.optString("version_name");
            final int versionCode = json.optInt("version_code");

            try {
                final int currentVersionCode = context.getPackageManager()
                        .getPackageInfo(context.getPackageName(), 0).versionCode;

                if (versionCode > currentVersionCode) {
                    if (!settings)
                        updateDialog.show();

                    updateDialog.setTitle(context.getString(R.string.update) + ' ' + versionName);

                    final TextView contentTV = (TextView) updateDialog.findViewById(R.id.tv_content_du);
                    contentTV.setTextColor(ContextCompat.getColor(context, MainActivity.themePrimaryTextColor));
                    contentTV.setText(Html.fromHtml(json.optString("content"), null, new Html.TagHandler() {

                        @Override
                        public void handleTag(boolean opening, String tag, Editable output,
                                XMLReader xmlReader) {
                            if ("li".equals(tag))
                                if (opening)
                                    output.append(" \u2022 ");
                                else
                                    output.append("\n");
                        }
                    }));

                    updateDialog.setCanceledOnTouchOutside(true);

                    updateDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);

                    updateDialog.getButton(AlertDialog.BUTTON_POSITIVE)
                            .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor));
                } else if (settings) {
                    updateDialog.setTitle(context.getString(R.string.update_no));

                    final TextView contentTV = (TextView) updateDialog.findViewById(R.id.tv_content_du);
                    contentTV.setTextColor(ContextCompat.getColor(context, MainActivity.themePrimaryTextColor));
                    contentTV.setText(Html.fromHtml(json.optString("content"), null, new Html.TagHandler() {

                        @Override
                        public void handleTag(boolean opening, String tag, Editable output,
                                XMLReader xmlReader) {
                            if ("li".equals(tag))
                                if (opening)
                                    output.append(" \u2022 ");
                                else
                                    output.append("\n");
                        }
                    }));

                    updateDialog.setCanceledOnTouchOutside(true);
                }
            } catch (NameNotFoundException e) {
                Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show();
            }
        } catch (JSONException e) {
            Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show();
        }
    } else if (settings) {
        updateDialog.cancel();

        final AlertDialog.Builder updateDialogBuilder = new AlertDialog.Builder(
                new ContextThemeWrapper(context, MainActivity.themeDialog));

        updateDialogBuilder.setTitle(context.getString(R.string.update));

        updateDialogBuilder.setMessage(R.string.error_update);

        updateDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                downloadAPK();
            }
        });

        updateDialogBuilder.setNegativeButton(android.R.string.no, null);

        final AlertDialog updateDialog = updateDialogBuilder.create();

        updateDialog.setCanceledOnTouchOutside(true);
        updateDialog.show();

        updateDialog.getButton(AlertDialog.BUTTON_POSITIVE)
                .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor));
        updateDialog.getButton(AlertDialog.BUTTON_NEGATIVE)
                .setTextColor(ContextCompat.getColor(context, MainActivity.accentSecondaryColor));
    }
}

From source file:com.ccjeng.weather.view.adapter.PlaceAutocompleteAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = super.getView(position, convertView, parent);

    // Sets the primary and secondary text for a row.
    // Note that getPrimaryText() and getSecondaryText() return a CharSequence that may contain
    // styling based on the given CharacterStyle.

    AutocompletePrediction item = getItem(position);

    TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
    TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
    textView1.setText(item.getPrimaryText(STYLE_BOLD));
    textView1.setTextColor(ContextCompat.getColor(getContext(), R.color.autocompleteTextColor));
    textView2.setText(item.getSecondaryText(STYLE_BOLD));
    textView2.setTextColor(ContextCompat.getColor(getContext(), R.color.autocompleteTextColor));

    return row;/*from  w ww  .jav  a  2  s.  co  m*/
}

From source file:com.spoiledmilk.ibikecph.favorites.FavoritesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View view = inflater.inflate(getListRowLayout(), parent, false);
    TextView tv = (TextView) view.findViewById(R.id.textFavoriteName);
    String name = getItem(position).getName();
    if (name.length() > 19)
        name = name.substring(0, 19) + "...";
    tv.setText(name);/*w  w w  .j a va2 s  .  c o m*/
    tv.setTypeface(IbikeApplication.getNormalFont());
    tv.setTextColor(getTextColor());
    ImageButton btnEdit = (ImageButton) view.findViewById(R.id.btnEdit);
    final FavoritesData fd = getItem(position);
    tv.setPadding(getPadding(fd), 0, 0, 0);
    btnEdit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            fragment.onEditFavorite(fd);
        }

    });

    final ImageView imgIcon = ((ImageView) view.findViewById(R.id.icon));

    if (!isEditMode) {
        imgIcon.setImageResource(getIconResourceId(getItem(position)));
        btnEdit.setVisibility(View.GONE);
    } else {
        imgIcon.setImageResource(R.drawable.fav_reorder);
        btnEdit.setVisibility(View.VISIBLE);
    }

    return view;
}

From source file:com.bryan.example.widget.slidingtablayout.SlidingTabLayout.java

/**
 * ???/*from   ww w. j  av  a2s.  c o m*/
 */
private void updateSelectedTitle(int position) {
    final PagerAdapter adapter = mViewPager.getAdapter();
    for (int i = 0; i < adapter.getCount(); i++) {
        final View tabView = mTabStrip.getChildAt(i);
        if (TextView.class.isInstance(tabView)) {
            TextView titleView = (TextView) tabView;
            boolean isSelected = i == position;
            titleView.setTextColor(isSelected ? mSelectedTextColor : mDefaultTextColor);
        }
    }
}

From source file:at.wada811.android.library.demos.view.ViewPagerAdapter.java

@Override
public View instantiateItem(ViewGroup container, int position) {
    View page = mInflater.inflate(R.layout.layout_page, container, false);
    TextView textView = (TextView) page.findViewById(R.id.text);
    int rgb = position * 255;
    int r = (rgb >> 16) & 0xFF;
    int g = (rgb >> 8) & 0xFF;
    int b = rgb & 0xFF;
    r = g * 5 % 256;/*from ww w . j  a v  a2s.c  om*/
    g = b * 15 % 256;
    b = r * 25 % 256;
    int argb = Color.argb(255, r, g, b);
    textView.setText(String.format("#%02X%02X%02X", r, g, b));
    textView.setTextColor(r > 192 || g > 192 || b > 192 ? Color.BLACK : Color.WHITE);
    page.setBackgroundColor(argb);
    container.addView(page);
    return page;
}