How I can write mathematical expression on EditText?

问题: I'm new at this forum, this is my first post. So, I've created an app with custom keyboard that displays, mathematical characters , such as integrals, sinus, power ... .Aft...

问题:

I'm new at this forum, this is my first post. So, I've created an app with custom keyboard that displays, mathematical characters , such as integrals, sinus, power ... .After that , I wanted to insert these characters on a EditText , that works fine , but the problem is I wanted to create a mathematical expression something like this https://ibb.co/F7j22BY.

What I have tried: - I have tried Mathjax, which is for web and not for mobiles , so the only way is to show the expression on a webview, and it's not what I really wan't.


回答1:

jqMath is a JavaScript module that makes it easy to put formatted mathematical expressions in your activity. you can download it online. download Jqmath from this link


回答2:

Check out this library. https://github.com/jianzhongli/MathView

To add this library to your project, go to your build.gradle (module) and add:

implementation 'io.github.kexanie.library:MathView:0.0.6'

Then define MathView in XML Layout File

<LinearLayout ...>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Formula two: from Java String with KaTeX"
    android:textStyle="bold"/>

<io.github.kexanie.library.MathView
    android:id="@+id/formula_two"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    auto:engine="KaTeX"
    >
</io.github.kexanie.library.MathView>

Then, configure it in your Code.

public class MainActivity extends AppCompatActivity {
MathView formula_two;
String tex = "This come from string. You can insert inline formula:" +
        " \(ax^2 + bx + c = 0\) " +
        "or displayed formula: $$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}$$";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
    super.onResume();

    formula_two = (MathView) findViewById(R.id.formula_two);
    formula_two.setText(tex);
    editText.setHint(formula_two.getText().toString());
 }
}

to set EditText hint just use editText.setHint(formula_two.getText().toString) So you could make the MathView Invisible somewhere but retrieve its text

  • 发表于 2019-03-18 20:59
  • 阅读 ( 301 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除