2016-07-29 129 views
6

我試圖將頁面內容加載到webview,頁面內容引用AngularJS和Angular Material中。當我在我的電腦上進行調試時運行它時,它可以通過Android模擬器正常工作。但是當我將它安裝在我的智能手機上時,它不起作用。它似乎並不知道JavaScript庫。非常感謝您的幫助。AngularJS不能在Xamarin中工作Android Webview

MainActivity.cs:

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Set our view from the "main" layout resource 
     SetContentView(Resource.Layout.Main); 

     var webView = FindViewById<WebView>(Resource.Id.webView); 
     webView.Settings.JavaScriptEnabled = true; 
     //webView.Settings.CacheMode = CacheModes.Normal; 
     webView.Settings.DomStorageEnabled = true; 
     webView.Settings.SetSupportMultipleWindows(true); 
     webView.Settings.JavaScriptCanOpenWindowsAutomatically = true; 
     webView.Settings.AllowContentAccess = true; 
     webView.Settings.AllowFileAccess = true; 
     webView.Settings.AllowFileAccessFromFileURLs = true; 
     // webView.SetWebChromeClient(new WebChromeClient()); 
     webView.SetWebViewClient(new WebViewClient()); 


     webView.LoadUrl("file:///android_asset/Content/List.html"); 

    } 

List.html:

<html> 
<head> 
    <title>Angular JS Directive</title> 
    <link href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.css" rel="stylesheet"></link> 
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"></link> 
    <style type="text/css"> 
     .listdemoListControls md-divider { 
      margin-top: 10px; 
      margin-bottom: 10px; 
     } 

     .listdemoListControls md-list-item > p, .listdemoListControls md-list-item > .md-list-item-inner > p, .listdemoListControls md-list-item .md-list-item-inner > p, .listdemoListControls md-list-item .md-list-item-inner > .md-list-item-inner > p { 
      -webkit-user-select: none; 
      /* Chrome all/Safari all */ 
      -moz-user-select: none; 
      /* Firefox all */ 
      -ms-user-select: none; 
      /* IE 10+ */ 
      user-select: none; 
      /* Likely future */ 
     } 
    </style> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.4/angular-material.min.js"></script> 

    <script> 

     angular.module('MyForm', ['ngMaterial']) 
     .config(function($mdIconProvider) { 
      $mdIconProvider 
      .iconSet('social', 'img/icons/sets/social-icons.svg', 24) 
      .iconSet('device', 'img/icons/sets/device-icons.svg', 24) 
      .iconSet('communication', 'img/icons/sets/communication-icons.svg', 24) 
      .defaultIconSet('img/icons/sets/core-icons.svg', 24); 
     }) 
     .controller('ListCtrl', function($scope, $mdDialog) { 
      $scope.liststudent= [ 
        { name: 'Kevin', isgirl: false }, 
        { name: 'Sara', isgirl: true}, 
        { name: 'Bob', isgirl: false }, 
        { name: 'Laura', isgirl: true }, 
        { name: 'Peter', isgirl: false } 
       ]; 
     }); 
    </script> 
</head> 
<body ng-app="MyForm"> 
    <md-list ng-cloak="" ng-controller="ListCtrl"> 
     <md-subheader class="md-no-sticky">Student list</md-subheader> 
     <md-list-item ng-repeat="topping in liststudent"> 
      {{ topping.name }} <br /> 
      <md-checkbox class="md-secondary" ng-model="topping.isgirl"></md-checkbox> 
     </md-list-item> 
     <md-divider></md-divider> 
     <md-list> 

     </md-list> 
    </md-list> 
</body> 
</html> 

截圖運行在手機:

enter image description here 截圖運行在計算機:

enter image description here

回答

2

它可能是一個網絡相關的問題。你有沒有嘗試在本地複製庫?

PS。我還沒有足夠的評論來評論,所以我發佈了這個答案。哈哈

+0

在我的智能手機上,我只通過運行文件「loadcontent.loadcontent-Signed.apk」來安裝應用程序,學生列表是靜態數據 –

+0

我的意思是javascript庫,請嘗試下載並將其合併到應用程序中,而不是從cdn獲取它們。您也可以嘗試通過webview加載託管網站。 – Barak

+0

謝謝!現在它工作正常。 –