简体   繁体   English

为什么我的 WebView 中没有加载我的 CSS 和 PHP 包含

[英]Why does my CSS and PHP include not load in my WebView

I use a WebView in my app.我在我的应用程序中使用WebView 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.我能够构建APK并将应用程序安装到我的设备上,但是当我离线启动应用程序时,它只显示正文PHP ,但它没有调用/加载CSS文件或包含PHP文件。

Directory structure in Android Studio : Android Studio 中的目录结构:

在此处输入图片说明

This is my MainActivity :这是我的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 does not ship with a PHP server. Android 不附带PHP服务器。 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.您需要重写离线页面才能在没有任何PHP代码的情况下运行。

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包含的一部分,因此不会出于同样的原因加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM