h5學習-h5嵌入android中


嵌入Android中的h5界面:

將此頁面復制到android項目中的assets目錄下邊:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        div{
           width: 10px;
            height: 20px;
            background-color: aquamarine;
        }
      /*  關鍵幀的定義*/
        @-webkit-keyframes mycolor {
            0%{
                background-color: #D2D2D2;
            }
            10%{
                background-color: #646464;
                width: 10px;
            }
            20%{
                background-color: aqua;
                width:20px ;
            }
            80%{
                background-color: #e54d26;
                width: 160px;
            }
            100%{
                background-color: blueviolet;
                width: 200px;
            }
        }

        div:hover{
            -webkit-animation-name: mycolor;
            -webkit-animation-duration: 5s;
            -webkit-animation-timing-function: linear;
            -moz-animation-iteration-count:infinite;
        }
    </style>
</head>
<body>
<div></div>
</body>
</html>

android中的界面:

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.sinawebpan.MainActivity" >

    <WebView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
       android:id="@+id/webview"
    />

</RelativeLayout>

MainActivity.java

public class MainActivity extends Activity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //將屏幕設置為全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        webView = (WebView) findViewById(R.id.webview);
loadLocalUrl("http://www.baidu.com"); loadLocalUrl(
"file:///android_asset/cssanimation.html");//本地的頁面要放在assets目錄下 } private void loadLocalUrl(String url) { WebSettings ws = webView.getSettings();
//如果訪問的頁面中有javastripts,則webview必須支持javascripts. ws.setJavaScriptEnabled(
true); webView.loadUrl(url); } }

 

知識點整理:

瀏覽器引擎WebKit,有很好的網頁解析機制。

WebKit包中的幾個重要的類:

  WebSettings:設置webview的特征、屬性

  WebView:顯示web頁面的視圖對象,用於網頁數據的載入、顯示等操作

      loadUrl(String url);//url 互聯網用http://www.google.com    本地用:file:///android_asset/xxx.html

      loadData();

      goBack();//返回上個頁面

      clearHistory();//清除歷史記錄

  WebViewClient:在web視圖中幫助處理各種通知、請求事件

  WebChromClient:輔助webview處理js對話框、網站標題、加載進度條等

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM