validar texto studio salto que obtener mascara linea eventos edittext datos color cambiar caja android uitextview textview

texto - salto de linea edittext android



¿Cómo puedo cambiar el color de una parte de un TextView? (7)

¡Es bueno para mi!

Spannable spannable = new SpannableString("ABC In-Network DEF"); String str = spannable.toString(); iStart = str.indexOf("In-Network"); iEnd = iStart + 10;/*10 characters = in-network. */ SpannableString ssText = new SpannableString(spannable); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View widget) { //your code at here. } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(true); ds.setColor(getResources().getColor(R.color.green)); } }; ssText.setSpan(clickableSpan, iStart, iEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mTextView.setText(ssText); mTextView.setMovementMethod(LinkMovementMethod.getInstance()); mTextView.setHighlightColor(Color.TRANSPARENT); mTextView.setEnabled(true);

text = text + CepVizyon.getPhoneCode() + "/n/n" + getText(R.string.currentversion) + CepVizyon.getLicenseText(); activationText.setText(text); myTextView.setText(text);

Quiero cambiar el color de la CepVizyon.getPhoneCode() de CepVizyon.getPhoneCode() . ¿Cómo puedo hacer esto?


Aquí hay una función de colorize basado en la respuesta de andyboot:

/** * Colorize a specific substring in a string for TextView. Use it like this: <pre> * textView.setText( * Strings.colorized("The some words are black some are the default.","black", Color.BLACK), * TextView.BufferType.SPANNABLE * ); * </pre> * @param text Text that contains a substring to colorize * @param word The substring to colorize * @param argb The color * @return the Spannable for TextView''s consumption */ public static Spannable colorized(final String text, final String word, final int argb) { final Spannable spannable = new SpannableString(text); int substringStart=0; int start; while((start=text.indexOf(word,substringStart))>=0){ spannable.setSpan( new ForegroundColorSpan(argb),start,start+word.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE ); substringStart = start+word.length(); } return spannable; }


Con respecto a la respuesta de Maneesh, esto funcionará, pero debes agregar y escapar las comillas para el atributo de color.

myTextView.setText(Html.fromHtml(text + "<font color=/"#FFFFFF/">" + CepVizyon.getPhoneCode() + "</font><br><br>" + getText(R.string.currentversion) + CepVizyon.getLicenseText()));


Si tiene texto estático que necesita color, puede agregarlo sin ningún código a través del archivo de cadenas:

<string name="already_have_an_account">Already have an account? <font color=''#01C6DB''>Login</font></string>

entonces

<TextView android:layout_width="wrap_content" android:layout_height="64dp" android:text="@string/already_have_an_account"/>

resultado

no estoy seguro de en qué versiones de API funciona, pero no funciona para api 19 que he probado hasta ahora, por lo que probablemente solo algunas de las versiones de API más recientes admitan esto

editar: como @hairraisin mencionó en los comentarios, intente usar fgcolor lugar de color para el color de la fuente, luego debería funcionar para niveles de API más bajos, pero necesita más pruebas para estar seguro


Una forma es dividir myTextView en pocos TextViews separados, uno de los cuales sería solo para el código del teléfono. Entonces controlar el color de este TextView específico es bastante directo.


Spannable es más flexible:

String text2 = text + CepVizyon.getPhoneCode() + "/n/n" + getText(R.string.currentversion) + CepVizyon.getLicenseText(); Spannable spannable = new SpannableString(text2); spannable.setSpan(new ForegroundColorSpan(Color.WHITE), text.length(), (text + CepVizyon.getPhoneCode()).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); myTextView.setText(spannable, TextView.BufferType.SPANNABLE);


myTextView.setText(Html.fromHtml(text + "<font color=white>" + CepVizyon.getPhoneCode() + "</font><br><br>" + getText(R.string.currentversion) + CepVizyon.getLicenseText()));