Rich Text Box in android

2019-02-14 18:55发布

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.

3条回答
祖国的老花朵
2楼-- · 2019-02-14 19:23

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)

查看更多
Root(大扎)
3楼-- · 2019-02-14 19:28

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.

查看更多
ゆ 、 Hurt°
4楼-- · 2019-02-14 19:31

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);
查看更多
登录 后发表回答