How to trim above message of loading data from WebView in android

I am new to android development. I am trying to develop an application to view a mathematical formula. My app shows the formula in WebView

, but use javascript

in the download message. I want to trim data loading posts from WebView

.

enter image description here

My xml code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EFEFEF"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp" >

<LinearLayout
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="#ffd0e3e5"
    android:gravity="center"
    android:paddingBottom="6dp"
    android:paddingTop="5dp" >

    <TextView
        android:id="@+id/textTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textColor="#ff33203d"
        android:textSize="18sp" />
</LinearLayout>

<WebView
    android:id="@+id/txtQuestion"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_below="@+id/topLayout"
    android:layout_weight="1" >
   </WebView> 
 </RelativeLayout>

      

My Java code:

  public class MainActivity extends Activity implements View.OnClickListener{

 private WebView txtQuestion;
 private String mathML;

private String doubleEscapeTeX(String s) {
String t="";
for (int i=0; i < s.length(); i++) {
    if (s.charAt(i) == '\'') t += '\\';
    if (s.charAt(i) != '\n') t += s.charAt(i);
    if (s.charAt(i) == '\\') t += "\\";
}
  return t;
 }

 @Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.examination_fragment_layout);
txtQuestion = (WebView) findViewById(R.id.txtQuestion);
txtQuestion.getSettings().setJavaScriptEnabled(true);

try {
    InputStream raw = getApplicationContext().getAssets().open(
            "multipale_choose.xml");
    QuizzesParser parser = new QuizzesParser(this);
    parser.startParsing(raw);
    answerList=parser.getpList();
   // initiateWebView(answerList.get(1).getAns_body(),txtQuestion);

    mathML="<p style='  height: 1000px;vertical-align: middle;text-align:center;'>";
mathML=mathML+answerList.get(1).getAns_body();

mathML=mathML+"</p>";   

txtQuestion=formulaWebview;
txtQuestion.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){

             txtQuestion.evaluateJavascript("javascript:document.getElementById('math').innerHTML='" +
                 doubleEscapeTeX(mathML)
                              +"';",null);


        }
        else{
            txtQuestion.loadUrl("javascript:document.getElementById('math').innerHTML='" +
                    doubleEscapeTeX(mathML)+"';");

        }

        txtQuestion.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
    }
});

final String mathJaxOfflineUrl = "file:///android_asset/MathJax/MathJax.js";            
txtQuestion.loadDataWithBaseURL("http://bar/", "<script type='text/x-mathjax-config'>"
        +"MathJax.Hub.Config({ " 
            +"showMathMenu: false, "
            +"jax: ['input/MathML','output/HTML-CSS'], " 

                     +"extensions: ['mml2jax.js'], " 
                      +"TeX: { extensions: ['noErrors.js','noUndefined.js'] }, "

          +"});</script>"
        +"<script type='text/javascript' "
          +"src='"+mathJaxOfflineUrl+"'"
          +"></script><span id='math'></span>","text/html","utf-8","");

  }catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
 }
}

      

I follow the example.

+3


source to share


1 answer


You add this code to your Webviews "loadDataWithBaseURL"



txtQuestion.loadDataWithBaseURL("http://bar/", "<script type='text/x-mathjax-config'>"
    +"MathJax.Hub.Config({ " 
    +"showMathMenu: false, "
    +"jax: ['input/MathML','output/HTML-CSS'], " 
    +"extensions: ['mml2jax.js'], " 
    +"TeX: { extensions: ['noErrors.js','noUndefined.js'] }, "
    +"messageStyle: 'none'"
    +"});</script>"
    +"<script type='text/javascript' "
    +"src='"+mathJaxOfflineUrl+"'"
    +">
   </script><span id='math'></span>","text/html","utf-8","");

      

+1


source







All Articles