I am trying to display square roots in my java mobile aplication. I tried with HTML by typing the code below. It displays the square root symbol but there is no line over the variable (√100). Is there a way to overline the variable (x). Thanks for your help :)
TextView.settext(Html.fromHtml("√ "+x));
5 Answers
You can try StrikethroughSpan like this:
textView.setText(x.toString(), TextView.BufferType.SPANNABLE);
Spannable spannable = (Spannable) textView;
spannable.setSpan(new StrikethroughSpan(), 0, 3, Spanned.SPAN_INCLUSIVE_INCLUSIVE);

- 329
- 1
- 3
- 7
Showing math formulas in Android might most easily be done by using a web view and then using MathML. For instance:
<math>
<msqrt>
<mn>100</mn>
</msqrt>
</math>
should show a well-formatted mathematical expression consisting of a square root of 100.
You can try it out here:
https://www.w3schools.com/code/tryit.asp?filename=GFAL3VTCXMCU
and then click run.
WebView and MathML may be overkill for your purposes, however, and it may also be a good idea to read or skim through https://developer.mozilla.org/en-US/docs/Web/MathML/Authoring as well as the drawbacks of using a WebView.

- 749
- 4
- 13
Inside:
TextView.settext(Html.fromHtml("√ "+x));
Add
<SPAN STYLE="text-decoration:overline">here the text has overline.</SPAN>
to your code for over-lined text. Instead of SPAN, you can use P or DIV.

- 598
- 1
- 8
- 24
I was able to do it with a little workaround from this answer.
Here is how it can be done for anyone coming later to this question
Step 1: Create a drawable file and name it whatever you wish to, in this case I am naming it as overline.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="-2dp"
android:left="-2dp"
android:right="-2dp"
android:top="1dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#030310" />
</shape>
</item>
</layer-list>
Step 2: Add the overline.xml as a background onto your TextView with android:background="@drawable/overline
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/overline"
android:textColor="#030310"
android:text="Hello"/>
Result:

- 130
- 1
- 9
I had the same issue. I am afraid, this has not worked for me:
<SPAN STYLE="text-decoration:overline">here the text has overline.</SPAN>
The suggestion may come from here?: https://html-shark.com/HTML/Overline.htm
I also came across this one which provides some more information on html supported tags: Html string with <style> tag and style in android textview
The overline span style seems to require css which is according to above linked discussion (unfortunately) not supported in Android.
The work around with the xml background line looks like a good looking solution but also did not work for me - I need overlined words randomly in strings.
Not looking perfect, but I have used overline each individual character instead now. However, this can leave gaps between different overlines. For example, to overline every character in the word 'Test', use:
editText.setText(Html.fromHtml("T̅e̅s̅t̅"));
other overline options on wikipedia: https://en.wikipedia.org/wiki/Overline
May work for others as well...

- 1
- 3