为什么我的CSS和PHP包含的内容未加载到我的WebView中 [英] Why does my CSS and PHP include not load in my WebView
问题描述
我在我的应用程序中使用 WebView
.当应用程序未连接到互联网时,我想在本地服务该站点.我能够构建 APK
并将其安装到设备上,但是当我离线启动应用程序时,它只是显示正文 PHP
,但未调用/load CSS
文件或包含 PHP
文件.
I use a WebView
in my app. When the app is not connected to the internet I want to serve the site locally. I was able to build the APK
and install the app onto my device, but when I start the app offline, it is just showing the body PHP
, but it did not call/load the CSS
File or include the PHP
files.
Android Studio中的目录结构:
Directory structure in Android Studio :
这是我的 MainActivity
:
public class Callback extends WebViewClient{
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Toast.makeText(getApplicationContext(), "No Internet Access!", Toast.LENGTH_SHORT).show();
view.loadUrl("file:///android_asset/nointernet.php");
}
}
这是我的没有互联网"页面
This is my "No Internet" page
<body>
<!-- Navigation Bar -->
<?php include 'assets\inc\navmobpage.php'; ?>
<!-- Page Content -->
<div class="container" align="center" style="background-color: white;padding-top: 50px;">
<img src="assets\img\nointernet.png" width="100%" />
<a class="btref" href="http://xx.xx.xx">REFRESH</a>
</div>
<?php include 'assets\inc\footmob.php'; ?>
<!-- Bootstrap core JavaScript -->
<script src="assets\general\jquery\jquery.min.js"></script>
<script src="assets\general\bootstrap\js\bootstrap.bundle.min.js"></script>
</body>
推荐答案
Android未随 PHP
服务器一起提供.因此,出于所有共同意图和目的,不可能在本地提供 .php
文件.
Android does not ship with a PHP
server. Therefore for all common intents and purposes, it is not possible to serve a .php
file locally.
您需要重写离线页面才能使用任何 PHP
代码.
You would need to rewrite your offline page to function without any PHP
code.
我假设您引用的 CSS
也是 PHP
include的一部分,因此出于相同的原因未加载.
I assume the CSS
you refer to is also part of the PHP
include and therefore is not loading for the same reason.
这篇关于为什么我的CSS和PHP包含的内容未加载到我的WebView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!