1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[android] Como utilizar arquivos HTML da pasta assets em uma WebView [fechada]

Discussão em 'Mobile' iniciado por Stack, Setembro 21, 2021.

  1. Stack

    Stack Membro Participativo

    Sei que existe diversas perguntas parecidas com essa, mas em todas elas não encontrei nenhum método que me ajudasse.

    Como está na 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");

    }
    }


    Como está no 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 da organização do projeto: [​IMG]

    Print de como fica o resultado final no Smartphone:

    [​IMG]

    Deveria ser carregado a expressão que está nesta linha

    var s = '$ax^2+bx+c=0$ with $a=0$';
    M.parseMath(s);
    document.write(s);

    Continue reading...

Compartilhe esta Página