android widget textview strikethrough

android - ¿Hay alguna manera fácil de atravesar el texto en un widget de aplicación?



textview strikethrough (14)

Me preguntaba si existe una manera fácil de insertar texto dentro de un widget de aplicación en Android. En una actividad normal, es bastante fácil, usando banderas textview:

textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

Pero dado que en un widget de aplicación, puedo usar solo vistas remotas ... No sé si esto es posible

Alguien sabe algo sobre esto?

¡Gracias!


Agregue la línea siguiente:

TextView tv=(TextView) v.findViewById(android.R.id.text1); tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

usa tu referencia en lugar de "tv"


Es realmente fácil si estás usando cadenas:

<string name="line"> Not crossed <strike> crossed </strike> </string>

Y luego solo:

<TextView ... android:text="@string/line" />


He hecho esto en un TextView regular (local), y debería funcionar en la variedad remota ya que los documentos muestran el método como equivalente entre los dos:

remote_text_view.setText(Html.fromHtml("This is <del>crossed off</del>."));


Intenté algunas opciones pero, esto funciona mejor para mí:

String text = "<strike><font color=/'#757575/'>Some text</font></strike>"; textview.setText(Html.fromHtml(text));

aclamaciones


Lo sé, estoy respondiendo a una vieja pregunta, podría ser útil para otra persona, por golpear una porción particular de TextView programáticamente.

TextView textView = (TextView) findViewById(R.id.textView); textView.setText("Text need to be set here", TextView.BufferType.SPANNABLE); Spannable spannable = (Spannable) textView.getText(); spannable.setSpan(new StrikethroughSpan(), 5, 8, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

Por lo tanto, en este código de ejemplo, 5 es la posición inicial y 8 es la posición final del texto que debe eliminarse, por lo que después de ejecutar este código podemos obtener el texto "necesario" con out out. Espero que sea útil para otra persona.


Otra forma de hacerlo programáticamente, que se parece menos a un hack que a Paint:

En lugar de hacer:

tv.setText(s);

hacer:

private static final StrikethroughSpan STRIKE_THROUGH_SPAN = new StrikethroughSpan(); ... tv.setText(s, TextView.BufferType.SPANNABLE); Spannable spannable = (Spannable) tv.getText(); spannable.setSpan(STRIKE_THROUGH_SPAN, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);


Para TextView multilínea, debe usar android.text.style.CharacterStyle de esta manera:

SpannableString spannable = new SpannableString(text); spannable.setSpan(new StrikethroughSpan(), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); remoteViews.setTextViewText(R.id.itemText, spannable);


Para hacer esto, puedes usar esto

title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

y para eliminar puede usar esto

title.setPaintFlags(title.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));


Para hacerlo programáticamente en una vista de texto, no probado en otras vistas >>

TextView tv = (TextView) findViewById(R.id.mytext); tv.setText("This is strike-thru"); tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);


Puedes usar esto:

remoteviews.setInt(R.id.YourTextView, "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);

Por supuesto, también puede agregar otros indicadores de la clase android.graphics.Paint.


Si tiene una sola palabra, podemos usar drawable. A continuación está el ejemplo:

<item android:state_pressed="false"><shape android:shape="line"> <stroke android:width="2dp" android:color="#ffffff" /> </shape> </item>

si tiene varias líneas, puede usar el siguiente código:

TextView someTextView = (TextView) findViewById(R.id.some_text_view); someTextView.setText(someString); someTextView.setPaintFlags(someTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG)


prueba este código

textview.setText((Html.fromHtml("<strike>hello world!</strike>")));


usted agrega:

TextView variableTv = (TextView) findViewById(R.id.yourText);

usted establece / agrega su variable:

variableTv.setText("It''s Text use Style Strike");

y luego agrega .setPaintFlags en variableTv:

variableTv.setPaintFlags(variableTv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);


Actualización de 2015: Amigos, esto es para versiones muy antiguas de Android. ¡Vea otras respuestas para soluciones modernas!

Para recorrer toda la vista de texto, puede usar una imagen de fondo específica para simular el efecto de tachado:

android:background="@drawable/bg_strikethrough"

Donde el bg_strikethrough es un parche de 9 que mantiene una línea sólida en el medio, creciendo en cualquier lado, con el relleno que creas razonable. He usado uno como este:

(ampliado para mayor claridad ... 1300%!)

Esa es mi versión HDPI, así que guárdela (la primera http://i.stack.imgur.com/nt6BK.png ) como res/drawable-hdpi/bg_strikethrough.9.png y la configuración funcionará de la siguiente manera: