java - jQuery Mobile 无法在 WebView 中工作

标签 java javascript android jquery jquery-mobile

我正在使用 jQuery mobile 和 html5。我想在 webview 中包含我的页面 DIstance2.html,但它显示为 html 页面,而不是 jQuery 移动页面。这是我在 Android 中使用 webview 的代码,我的 jQuery mobile 版本是 1.4.1 和 jQuery 1.11。

package com.example.webapp.com;

import com.example.webapp.com.R.string;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;

@SuppressLint("SetJavaScriptEnabled") public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String url="http://192.168.1.4/dream-html5/api/Distance2html.html";
        WebView wvSite = (WebView)findViewById(R.id.webview);


        //...on active JavaScript...
        wvSite.getSettings().setJavaScriptEnabled(true);
        wvSite.getSettings().setDomStorageEnabled(true);


        //...et on charge la page

        wvSite.loadUrl(url);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

最佳答案

在您的项目中添加一个 asset 文件夹并从那里调用您的 html url,例如 wvSite.loadUrl("file:///android_asset/dream-html5/api/Distance2html.html")

关于java - jQuery Mobile 无法在 WebView 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23366918/

相关文章:

javascript - 根据页面上突出显示的 div 自动向下滚动

java - 安卓测试: verify onClickListener using private anonymous class

android - 使用 MediaPlayer 类播放视频

android - MyLocationOverlay dispatchTap() 不传播

java - OpenJPA 增强 - 不支持 {0} Embeddable 中定义的身份字段

java - 为什么 assertThat 在检查字符串相等性时不能正常运行?

javascript - 基于哈希密码加密数据

java - 捕获 SAXParser 的字节数/偏移量

java - 我需要在 Eclipse 中编译 .java 文件才能运行应用程序吗?

javascript - 使用粘性导航调整窗口大小时横幅位置关闭