在机器人工作室简单的WebView应用程序错误机器人、应用程序、错误、工作室

2023-09-04 06:48:02 作者:这个女孩有点甜

我尽量让这个互动地图简单的WebView应用程序: http://gta5online.com/map/interactive >还有在地图下方的全屏链接。

i try to make a simple webview app for this interactive map: http://gta5online.com/map/interactive > there is also a fullscreen link below the map.

现在我创建了一个资产文件夹,其中包含在它的所有文件,图标,地图瓦片和html文件的互动的文件夹。

now i created an asset folder and included the "interactive" folder which has all the files, icons, map tiles and html document in it.

我想从那里加载HTML文档转换为活动作为一个web视图。所以它的本地文件。我想应用程序来处理它不是默认的浏览器。

i want to load the html document from there into a activity as a webview. so its a local file. i want the app to handle it not the default browser.

下面是我做的现在:

我创建了一个新的项目,并增加这些codeS到activity_home.xml文件:

i created a new project and added those codes into the activity_home.xml file:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("file:///android_asset/interactive/map.html");
/>

然后我加入这个code,使互联网接入体现,即使它,我要加载(供以后使用)本地HTML文档:

then i added this code to enable internet access in to manifest even if its a local html doc that i want to load (for later uses):

  <uses-permission android:name="android.permission.INTERNET"/>

我也启用JavaScript的在第一code座,你可以看到。

i also enabled javascript at the first code block as you can see.

我应该已经把一些code到home.java文件吗?

should i've put some code into the home.java file too?

在YT教程中,我看到,他用这样的事情在java文件:

in a YT tutorial i saw that he used something like this in the java file:

      #in mainactivity.java
    setContentView(R.layout.activity_main);
    String url ="file:///android_asset/interactive/map.html";
    WebView view=(WebView) this.findViewById(R.id.webView);
    view.getSettings() .setJavaScriptEnabled(true);
    view.loadUrl(url);

是否有人可以帮助一个noob通过解释我做错了什么,简单的步骤,如何完成这个程序来实现这一目标?我敢肯定,其简单的为你们即使它是对我来说很难。

can someone please help a noob to achieve this by explaining what i did wrong and simple steps how to complete this app?. i'm sure its simple for you guys even if its that hard for me.

推荐答案

要非常小心,在Android中,你永远无法把Java的code到XML code。

Be very careful in Android, you can never place Java code into XML code.

这code:

WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();

myWebView.loadUrl("file:///android_asset/interactive/map.html");
webSettings.setJavaScriptEnabled(true);