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:Main.java

public static void updateStatusBar(TextView statusBarMain, int color, String message) {
    if (statusBarMain != null) {
        statusBarMain.setTextColor(color);
        statusBarMain.setText(message);//from w ww .  j ava2 s. c o  m
        statusBarMain.setSelected(true);
        statusBarMain.invalidate();
    }
}

From source file:Main.java

public static void setTextViewAttributes(TextView textView, int size, int colorRes) {
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    textView.setTextColor(textView.getResources().getColor(colorRes));
}

From source file:Main.java

@SuppressLint("NewApi")
public static void setTextColor(Context ctx, TextView view, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        view.setTextColor(ctx.getResources().getColor(id, ctx.getTheme()));
    } else {//from   w  ww .  j  av a  2  s  .com
        view.setTextColor(ctx.getResources().getColor(id));
    }
}

From source file:Main.java

public static TextView createTextView(Context context, String text) {
    TextView tv = new TextView(context);
    tv.setPadding(10, 10, 10, 10);//  w ww  .  j  av  a 2  s.  c o  m
    tv.setText(text);
    tv.setGravity(Gravity.CENTER);
    tv.setTextSize(24);
    tv.setTextColor(Color.RED);
    return tv;
}

From source file:com.monmonja.library.utils.ViewUtils.java

public static void makeToast(Context context, int resId) {
    TypedValue tv = new TypedValue();
    int offsetY = 0;
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        offsetY = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }//from   w w w  . j  a  v a 2 s.c  o m

    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    View view = toast.getView();
    view.setBackgroundColor(context.getResources().getColor(R.color.toast_background));
    TextView text = (TextView) view.findViewById(android.R.id.message);
    text.setTextColor(context.getResources().getColor(android.R.color.white));
    toast.show();
}

From source file:Main.java

public static void showOkDialog(String title, String msg, Activity act) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(act);
    if (title != null) {

        TextView dialogTitle = new TextView(act);
        dialogTitle.setText(title);/*w  w  w. ja  v  a 2 s  .c  o  m*/
        dialogTitle.setPadding(10, 10, 10, 10);
        dialogTitle.setGravity(Gravity.CENTER);
        dialogTitle.setTextColor(Color.WHITE);
        dialogTitle.setTextSize(20);
        dialog.setCustomTitle(dialogTitle);

    }
    if (msg != null) {
        dialog.setMessage(msg);
    }
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });
    AlertDialog dlg = dialog.show();
    TextView messageText = (TextView) dlg.findViewById(android.R.id.message);
    messageText.setGravity(Gravity.CENTER);

}

From source file:Main.java

public static void setTabWidgetTitle(Context context, TabWidget tabWidget, int size, int color) {
    TextView tv = null;
    for (int i = 0, count = tabWidget.getChildCount(); i < count; i++) {
        tv = ((TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title));
        tv.setTextSize(size);//from   w  w w . j  a va  2s .  c  o  m
        tv.getPaint().setFakeBoldText(false);
        tv.setTextColor(context.getResources().getColorStateList(color));
    }
}

From source file:Main.java

public static void setTitle(TextView titleTv, int titleColor, int titleTextSize, int messageColor,
        int messageTextSize, CharSequence title, CharSequence message) {
    titleTv.setMinHeight(titleTextSize * 3);

    if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) {
        titleTv.setTextColor(titleColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
        titleTv.getPaint().setFakeBoldText(true);
        titleTv.setText(title);/*from   ww  w  . j  a va  2 s  .c  o m*/
    } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        titleTv.setTextColor(messageColor);
        titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize);
        titleTv.setText(message);
    } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        SpannableString titleSs = new SpannableString(title + "\n" + message);
        titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        titleTv.setText(titleSs);
        titleTv.setLineSpacing(0.0f, 1.2f);
    } else {
        titleTv.setVisibility(View.GONE);
    }
}

From source file:com.nagopy.android.xposed.utilities.ModBrightness.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@XMinSdkVersion(Build.VERSION_CODES.JELLY_BEAN_MR1)
@HandleInitPackageResources(targetPackage = XConst.PKG_SYSTEM_UI, summary = "??")
public static void brightnessDebugger(final String modulePath, final InitPackageResourcesParam resparam,
        final ModBrightnessSettingsGen settings) throws Throwable {
    if (!settings.brightnessDebugger) {
        return;/*from ww w.j  a  va 2 s . co m*/
    }

    resparam.res.hookLayout(XConst.PKG_SYSTEM_UI, "layout", "super_status_bar", new XC_LayoutInflated() {
        @Override
        public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable {
            LinearLayout parent = (LinearLayout) liparam.view
                    .findViewById(liparam.res.getIdentifier("system_icon_area", "id", XConst.PKG_SYSTEM_UI));

            // ?
            TextView luxTextView = new TextView(parent.getContext());
            luxTextView.setTextSize(8);
            luxTextView.setSingleLine(false);
            luxTextView.setTextColor(Color.WHITE);
            luxTextView.setText("");
            parent.setGravity(Gravity.CENTER_VERTICAL);
            parent.addView(luxTextView, 0);
            AutoBrightnessController autoBrightnessChangedReceiver = new AutoBrightnessController(luxTextView);
            IntentFilter intentFilter = new IntentFilter(
                    AutoBrightnessController.ACTION_AUTO_BRIGHTNESS_CHANGED);
            intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
            parent.getContext().registerReceiver(autoBrightnessChangedReceiver, intentFilter);
        }
    });
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static TextView getTextView(Context context, LinearLayout.LayoutParams params, StringBuffer buffer) {
    TextView textView = new TextView(context);
    textView.setTextColor(Color.BLACK);
    textView.setLayoutParams(params);//w w w .j  a  va2s  .  com
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setTextSize(getTextSize(context));
    textView.setText(Html.fromHtml(buffer.toString()));
    return textView;
}