I am creating an android app that uses the MathQuill library.
The application consists of a WebView that uses the MathQuill equation parser and a keybord (implemented via activity_main.xml and MainActivity.java) which has buttons that write math symbols to a WebView.
I need to create a backspace button functionality which I don't know how to do.
Backspace button in layout file:
<Button
android:id="@+id/button_backspace"
android:layout_width="35dp"
android:layout_height="35dp"
android:text="b"
android:background="@drawable/button"
android:padding="0dp"
android:textSize="15sp"
android:layout_margin="1dp"
/>
WebView in layout file:
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
/>
WebView init in MainActivity.java
et = (WebView) findViewById(R.id.web_view);
et.getSettings().setJavaScriptEnabled(true);
et.loadUrl("file:///android_asset/some.html");
Backspace button in MainActivity.java:
Button btn_backspace = (Button) findViewById(R.id.button_backspace);
btn_backspace.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
et.loadUrl("javascript:input(\"\\b\")");
}
});
Android asset html fragment:
var MQ = MathQuill.getInterface(2);
var mathField = MQ.MathField(mathFieldSpan, {
spaceBehavesLikeTab: true,
handlers: {
edit: function() {
mathField.focus()
//latexSpan.textContent = mathField.textContent
latexSpan.textContent = mathField.latex();
Android.getImageUrl(mathField.latex())
}
}
});
function input(str) {
if(str == "tangens"){
str = "\\tan"
}
mathField.cmd(str)
mathField.focus()
}
the input function is used to write math symbols to a WebView.
I tried sending a \b char with no success.
mathField.keystroke('Backspace')which you could then add a function such asjavascript:doBackspace()which performs same and called by button handler.