2012-03-14 6 views
2

私は記事を書いて提出するオプションを与えるアプリケーションを作成しています。edittextをandroidのhtmlエディタとして使用する

ユーザーがテキストの太字や斜体、下線などの部分を作ることができるように、すべてのhtmlオプションを提供したいと思います。 私はグーグルではありますが、それほど適切なオプションや、

提案を探しています。

答えて

4

あなたはこのために、以下のようなものを使用することができます。

ここ

textDisplayedBottomがTextViewのです。

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

これが役に立ちます。

EDIT 1:太字、斜体、下線のためのeditext提供するオプションあなたはいつもそれ

// 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); 

詳細を達成するためにSpannableを使用することができますするためのEditText

については

あなたは

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

+0

ここで見つけることができますしかし、私は編集テキスト自体にHTML形式のテキストを表示したい! –

+0

私の答えを編集しました。それが役立つかどうか確認してください。 – Deva

+0

thanks.solutionが私を助けます。 –

関連する問題