为什么我的 CSS 和 PHP 包含没有加载到我的 WebView 中
Why does my CSS and PHP include not load in my WebView
我在我的应用程序中使用 WebView
。当应用程序未连接到互联网时,我想在本地为网站提供服务。我能够构建 APK
并将该应用程序安装到我的设备上,但是当我离线启动该应用程序时,它只显示正文 PHP
,但没有 call/load CSS
归档或包含 PHP
个文件。
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");
}
}
这是我的 "No Internet" 页面
<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
文件。
您需要重写您的离线页面才能在没有任何 PHP
代码的情况下运行。
我假设您提到的 CSS
也是 PHP
包含的一部分,因此出于同样的原因没有加载。
我在我的应用程序中使用 WebView
。当应用程序未连接到互联网时,我想在本地为网站提供服务。我能够构建 APK
并将该应用程序安装到我的设备上,但是当我离线启动该应用程序时,它只显示正文 PHP
,但没有 call/load CSS
归档或包含 PHP
个文件。
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");
}
}
这是我的 "No Internet" 页面
<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
文件。
您需要重写您的离线页面才能在没有任何 PHP
代码的情况下运行。
我假设您提到的 CSS
也是 PHP
包含的一部分,因此出于同样的原因没有加载。