Framework7 inside webview页面未加载
Framework7 inside webview pages not loading
我是 framework7 的新手,我正试图让它在 android 上运行。
这是我所做的,在 android studio 中创建项目,加载 webview index.html 并且它有效。但是 "about"、"services" 和 "form" 页面的 link 不起作用。
我看到 framework7 使用 ajax 调用那些页面。
所以我认为它在 webview 中不起作用,对吗?
我是否需要更改 framework7 使用 javascript 或其他方式初始化加载页面的方式?
有可能让它那样工作吗?将另一个 html 文件的内容加载为页面而不使用 "inline" 页?
有什么建议吗?
使用我的代码更新(使用 android studio):
activity_main.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="atlasdb.atlasdatabase.MainActivity">
<WebView
android:id="@+id/atlasdatabase"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
MainActivity.java:
package app.apptest;
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);
WebView myWebView = (WebView) findViewById(R.id.apptest);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
myWebView.loadUrl("file:///android_asset/index.html");
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.apptest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
通过将这些行添加到 webSettings 来允许文件访问您的 webview:
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
示例项目:
Andorid-Framework7-StartKit 在 Github
我是 framework7 的新手,我正试图让它在 android 上运行。
这是我所做的,在 android studio 中创建项目,加载 webview index.html 并且它有效。但是 "about"、"services" 和 "form" 页面的 link 不起作用。
我看到 framework7 使用 ajax 调用那些页面。
所以我认为它在 webview 中不起作用,对吗?
我是否需要更改 framework7 使用 javascript 或其他方式初始化加载页面的方式?
有可能让它那样工作吗?将另一个 html 文件的内容加载为页面而不使用 "inline" 页?
有什么建议吗?
使用我的代码更新(使用 android studio):
activity_main.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="atlasdb.atlasdatabase.MainActivity">
<WebView
android:id="@+id/atlasdatabase"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
MainActivity.java:
package app.apptest;
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);
WebView myWebView = (WebView) findViewById(R.id.apptest);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDatabaseEnabled(true);
myWebView.loadUrl("file:///android_asset/index.html");
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.apptest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
通过将这些行添加到 webSettings 来允许文件访问您的 webview:
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);