Rich Text Box in android

2019-02-14 18:51发布

问题:

Is there any control in android which we can use as a rich text box which can handle formatting of characters such as bold, italic etc. and use fonts and color ?

If anyone having any link or source related to the above information please share it with me.

回答1:

SpannableString class or HTML.fromHtml() allows you to manipulate different styles in actual string. See the links below:

http://developer.android.com/reference/android/text/SpannableString.html http://developer.android.com/reference/android/text/Html.html#toHtml(android.text.Spanned)



回答2:

Sample SpannableString & TextView implementation:

    TextView tv = new TextView;
    String text = "String String String String body";
    SpannableString spannableStr = new SpannableString(text);
    spannableStr.setSpan(new StyleSpan(Typeface.BOLD), 0 , 10, 0);
    tv.setText(spannableStr);


回答3:

WebView is the closest that I can think of, but it is super duper heavy unless you want the entire screen to be a webview.