3
mTextView.setText(Html.fromHtml("26<ruby>日<rt>にち</rt></ruby>から"));

But Html.fromHtml doesn't support ruby element well. <rt> elements will be omitted in the textview. Is there any workaround? I have a list of such TextView, so WebView is inefficient.

Edit: I tried WebView, and it worked better than I thought. Be careful with encodings.

Community
  • 1
  • 1
Zen
  • 5,065
  • 8
  • 29
  • 49

2 Answers2

3

Android seems support the following HTML tags to be rendered on TextView.

<a href=”…”> <b>,  <big>, <blockquote>, <br>, <cite>, <dfn>
<div align=”…”>,  <em>, <font size=”…” color=”…” face=”…”>
<h1>,  <h2>, <h3>, <h4>,  <h5>, <h6>
<i>,  <img src=”…”>,  <p>, <small>
<strike>,  <strong>, <sub>, <sup>, <tt>, <u>

So ruby tag is not supported in here .

  • Is there any workaround? For your ruby -NO
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    You mean there is no easy way to display ruby? That's crucial – Zen May 23 '16 at 10:51
  • 1
    I see [NHK Easy Japanese News](https://play.google.com/store/apps/details?id=com.aovill.language.e2l.ejn) looks like using `ruby`. What tools can I use to find which widget it's using? – Zen May 23 '16 at 12:33
0

This project called RubySpan has a solution. It does this by extending ReplacementSpan.

RubySpan is an attempt to display ruby annotation along with text using Android TextView. Compared to the WebView solution, using RubySpan with TextView is a lot faster, flexible and more friendly to layouts. Current implementation focuses on displaying furigana on Japanese kanji. But you can easilly adapt it to your application. The minimal API supported is API 21 (Android 5.0 Lollipop). Since layouting text is a complex thing, there're still some bugs and the result is not perfect if you compare it with that produced by the browser or WebView.

Artemious
  • 1,980
  • 1
  • 20
  • 31