2012-03-14 3 views
2

Je crée une application qui donne des options pour écrire des articles et soumettre.Utilisez edittext comme éditeur html dans android

Je veux donner toutes les options html à l'utilisateur afin que l'utilisateur puisse faire une partie du texte gras, italique, souligné etc. j'ai googlé mais pas trouvé beaucoup d'options appropriées ou tout outil html pour android.

recherchant des suggestions.

Répondre

4

Vous pouvez utiliser quelque chose comme ci-dessous pour cela:

Ici textDisplayedBottom est un TextView.

actualStringToDisplay="font COLOR=\"RED\"><b>"+yourString</b></font>"; 
textDisplayedBottom.setText(Html.fromHtml(actualStringToDisplay)); 

Espérons que cela aide.

EDIT 1: Pour EditText

Pour EditExt offrant des options pour italique souligner gras, vous pouvez toujours utiliser Spannable pour y parvenir

// Get our EditText object. 
EditText vw = (EditText)findViewById(R.id.text); 

// Set the EditText's 
text.vw.setText("Italic, highlighted, bold."); 

// If this were just a TextView, we could do: 
// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE); 
// to force it to use Spannable storage so styles can be attached. 
// Or we could specify that in the XML. 
// Get the EditText's internal text storage 

Spannable str = vw.getText(); 

// Create our span sections, and assign a format to each. 

str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

Les détails que vous pouvez trouver ici

http://developer.android.com/resources/faq/commontasks.html#selectingtext

+0

mais je veux afficher le texte au format html dans le texte d'édition lui-même! –

+0

Édité ma réponse. Vérifiez si cela aide. – Deva

+0

thanks.solution m'aide. –