[英]Android webview and load different pages inside the app
我有一個關於 webview 的問題。 我會盡力解釋。
我有一個網站,我想用 webview 顯示該網站(所有文件都是從應用程序本身加載的,而不是從網絡加載的)。
我讓它工作,但我在加載其他文件時遇到了問題。
我有一個用於 1 月 (html) 的計算器,並且可以正常工作,但是例如,對於 2 月,它會加載與 1 月插入的相同數據。
我嘗試創建 12 個不同的文件夾,每個文件夾都有自己的計算器文件,因此它加載單獨的 html/css,但它仍然無法正常工作,即每個月加載不同的數據。
我有我在互聯網上找到的這段代碼(順便說一句,我沒有這方面的編碼經驗,我只是嘗試自學並盡我所能讓它以某種方式工作)。
Android 清單:
<manifest
package="com.example.com"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="app"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name="com.example.com.MainActivity"
android:label="app" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
主要活動布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/activity_main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
活動:
package com.example.com;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView mWebView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = findViewById(R.id.activity_main_webview);
mWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.loadUrl("file:///android_asset/index.html");
}
}
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
我知道它在那里指的是 INTERNET,但我不知道如何使它工作,因為它會給出錯誤並且如果我刪除這些行將不會編譯。
對不起,但這並不能解決問題。 讓我嘗試更詳細地解釋:
我有 12 個文件夾,其中包含 html、css 和 js。
現在的例子:文件夾一月,我插入我想要的數據。 如果我離開或關閉應用程序,當我再次打開它時,我在其中插入的數據(這是一個帶有時間的下拉列表)它會在特定字段中加載我放在那里的數據。
現在,如果我打開文件夾二月,它會加載我在一月文件夾中插入的相同數據,而不是我在二月插入的數據。 事實上,如果我編輯二月文件夾中的文件,一月文件夾也會受到影響,就像它始終是同一個文件而不是分開的文件/文件夾一樣。
電離
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.