How can I change the color of text of a MathView? Which is basically a WebView

1.6k views Asked by At

Here is the project: github.com/kexanie/MathView

I have only found a method to change the background and forefround colors.

XML:

<io.github.kexanie.library.MathView
        android:id="@+id/formula"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        auto:text="\\(ax^2 + bx + c = 0\\) "
        auto:engine="KaTeX"
>
</io.github.kexanie.library.MathView>

Java:

MathView formula;
formula = (MathView) findViewById(R.id.formula);
String tex = " \\(ax^2 + bx + c = 0\\) ";
formula.setText(tex);
3

There are 3 answers

0
james On

Here is the answer:

First change the config:

formula.config(
    "MathJax.Hub.Config({\n"+
    "  { TeX: { extensions: [\"color.js\"] } }\n"+
    "});"
);

Then:

formula.setText("\\(\\color{white}{ax^2 + 7}\\)");

Just change white to what you need.

0
Arshdeep Singh On

I have used MathJax engine for this

<io.github.kexanie.library.MathView
            android:id="@+id/formula_one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/colorGrey"
            auto:text="\\(\\color{Gray}{When a \\ne 0\\, there are two solutions to \\(ax^2 + bx + c = 0\\)
    and they are $$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$}\\)"
            auto:engine="MathJax">

        </io.github.kexanie.library.MathView>

This way you can directly set text from XML and no need to change config :)

0
Ahmed Rajab On

Since Math View extends Web View so the question is how to change of textcolor of a Web View https://stackoverflow.com/a/34386257/8272646 this answer helped me, I used hexa decimal format of the color (ex. white: #ffffff)