2
I know there are several similar questions, but in all of them I have found no method to help me.
As it is in Activity:
package com.example.guilherme.webviewteste;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webTeste();
}
public void webTeste(){
WebView webView = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
String path="file:///assets/mathscribe/";
String js = "<html><head>" + "<link rel='stylesheet' href='"+path+"jqmath-0.4.3.css'>"+"<script src='"
+path+"jquery-1.4.3.min.js'></script>"+"<script src='"+path+"jqmath-etc-0.4.5.min.js'></script>"+
"</head><body>"+"<script> var s = '$ax^2+bx+c=0$ with $a=0$' M.parseMath(s);document.write(s);</script></body></html>";
webView.loadData(js, "text/html", "UTF-8");
}
}
As it is in XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.guilherme.webviewteste.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_marginTop="0dp"/>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview1"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp">
</WebView>
Print of the project organization:
Print how the final result is in Smartphone:
Should be loaded the expression that is on this line
<script>
var s = '$ax^2+bx+c=0$ with $a=0$' M.parseMath(s);document.write(s);
</script>
Just in case, put some html inside your body and tell me if the screen is still blank
– Guilherme Nascimento
@Guilhermenascimento I did a test and it worked, what could be the problem then? Now I got much more lost :/
– Guilherme HS
Guilhermehs I think something like this has happened to me, when compiling and running somehow does not update the app in the emulator
– Guilherme Nascimento
Try to use the
loadDataWithBaseURL
pass thepath
asbaseUrl
and their<script src='"+path+"...
just put<script src='./seuarquivo.js'>
. If this does not work you can also try to create an index.html in this directory and use theloadUrl()
usingfile:///assets/mathscribe/index.html
as url– Icaro Martins