textsize textcapcharacters settextsize inputtype code android text highlight textview

android - settextsize - textcapcharacters



¿Destaca el color del texto usando Html.fromHtml() en Android? (7)

Estoy desarrollando una aplicación en la que habrá una pantalla de búsqueda en la que el usuario puede buscar palabras clave específicas y esa palabra clave debe resaltarse. He encontrado el método Html.fromHtml.

Pero me gustaría saber si es la forma correcta de hacerlo o no.

Por favor, hágame saber su opinión sobre esto.


Esto se puede lograr usando una cadena Spannable. Deberá importar los siguientes

import android.text.SpannableString; import android.text.style.BackgroundColorSpan; import android.text.style.StyleSpan;

Y luego puede cambiar el fondo del texto usando algo como lo siguiente:

TextView text = (TextView) findViewById(R.id.text_login); text.setText(""); text.append("Add all your funky text in here"); Spannable sText = (Spannable) text.getText(); sText.setSpan(new BackgroundColorSpan(Color.RED), 1, 4, 0);

Donde esto resaltará los caracteres en las posiciones 1 - 4 con un color rojo. ¡Espero que esto ayude!


Solución alternativa: utilizando un WebView en su lugar. Html es fácil de trabajar.

WebView webview = new WebView(this); String summary = "<html><body>Sorry, <span style=/"background: red;/">Madonna</span> gave no results</body></html>"; webview.loadData(summary, "text/html", "utf-8");


Usar el valor de color del recurso xml:

int labelColor = getResources().getColor(R.color.label_color); String сolorString = String.format("%X", labelColor).substring(2); // !!strip alpha value!! Html.fromHtml(String.format("<font color=/"#%s/">text</font>", сolorString), TextView.BufferType.SPANNABLE);


la fuente está obsoleto use span en lugar de Html.fromHtml ("" + content + "")


O mucho más simple que tratar con Spannable manual, ya que no dijiste que quieres resaltar el fondo, solo el texto:

String styledText = "This is <font color=''red''>simple</font>."; textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);


String name = modelOrderList.get(position).getName(); //get name from List String text = "<font color=''#000000''>" + name + "</font>"; //set Black color of name /* check API version, according to version call method of Html class */ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) { Log.d(TAG, "onBindViewHolder: if"); holder.textViewName.setText(context.getString(R.string._5687982) + " "); holder.textViewName.append(Html.fromHtml(text)); } else { Log.d(TAG, "onBindViewHolder: else"); holder.textViewName.setText("123456" + " "); //set text holder.textViewName.append(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY)); //append text into textView }


textview.setText(Html.fromHtml("<font color=''rgb''>"+text contain+"</font>"));

Le dará al color exactamente lo que ha hecho en el editor de html, simplemente configure la vista de texto y concatúrela con el valor de la vista de texto. Android no es compatible con el color de span, cámbielo a color de fuente en el editor y ya está listo para comenzar.