Android: html en textview con el enlace clickable

Yo uso un a-htmltag en mi TextView , pero cuando TextView en él nada sucede.

¿Cómo puedo abrir el navegador web con la url?

Prueba esto

 txtTest.setText( Html.fromHtml("<a href=\"http://www.google.com\">Google</a>")); txtTest. setMovementMethod(LinkMovementMethod.getInstance()); 

Recuerde: no utilice android: autoLink = atributo "web" con él. Porque causa LinkMovementMethod no funciona.

Actualización para SDK 24+ La función Html.fromHtml obsoleta en Android N (SDK v24), por lo que Html.fromHtml utilizar este método:

  String html = "<a href=\"http://www.google.com\">Google</a>"; Spanned result; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { result = Html.fromHtml(html,Html.FROM_HTML_MODE_LEGACY); } else { result = Html.fromHtml(html); } txtTest.setText(result) txtTest. setMovementMethod(LinkMovementMethod.getInstance()); 

Aquí está la lista de banderas:

Public static final int FROM_HTML_MODE_COMPACT = 63; Public static final int FROM_HTML_MODE_LEGACY = 0; Public static final int FROM_HTML_OPTION_USE_CSS_COLORS = 256; Public static final int FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = 32; Public static final int FROM_HTML_SEPARATOR_LINE_BREAK_DIV = 16; Public static final int FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = 2; Public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST = 8; Public static final int FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = 4; Public static final int FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = 1; Public static final int TO_HTML_PARAGRAPH_LINES_CONSECUTIVE = 0; Public static final int TO_HTML_PARAGRAPH_LINES_INDIVIDUAL = 1;

Ver esta entrada de blog , puede ser su lo que está buscando.

  • Agregar una fuente personalizada para la aplicación completa de Android
  • ¿Cómo puedo interactuar con el diseño de Lockscreen para mostrar texto en él, como esta aplicación:
  • Cómo ajustar el tamaño de la fuente del texto para que se ajuste a textview
  • Espaciado de párrafos con SpannableStringBuilder en TextView
  • Desplazamiento por programación de una palabra en vista en una vista de texto
  • Cómo configurar el estilo de fuente en negrita, cursiva y subrayado en un Android TextView?
  • Tener un problema al eliminar TextViews de un LinearLayout mediante programación
  • Cómo obtener las coordenadas XY y el tamaño de píxeles de un TextView?
  • Cómo capturar una excepción (ActivityNotFoundException) durante el uso de LinkMovementMethod
  • Android scrollview autoscrolling como texto se añade
  • TextView con diferentes textSize
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.