zoukankan      html  css  js  c++  java
  • Phonegap 原生控件(Android)与html混合

    1. 用命令创建cordova项目

    cordova coreate hello com.example.hello hello

    2.打开MainActivity

    在onCreate方法中加入

    setContentView(R.layout.main_activity);

    3. main_activity文件如下:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="45dip"
            android:background="#25C28B" >
    
            <ImageButton
                android:id="@+id/cordova_back"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="#00FFFFFF"
                android:paddingLeft="10dp"
                android:paddingRight="20dp"
                android:src="@drawable/back_all" />
    
            <TextView
                android:id="@+id/cordova_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="原生头部"
                android:textColor="#FFFFFF"
                android:textSize="20sp" />
    
            <Button
                android:id="@+id/btn_report"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:background="#00FFFFFF"
                android:paddingLeft="10dp"
                android:paddingRight="20dp"
                android:text="报告"
                android:textColor="#FFFFFF"
                android:textSize="20sp" />
        </RelativeLayout>
    
        <org.apache.cordova.engine.SystemWebView
            android:id="@+id/cordovaWebView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </LinearLayout>
    

      SystemWebView是一个扩展的webview

    4. 重新makeWebView方法和createViews方法

      @Override
        protected CordovaWebView makeWebView() {
            SystemWebView webView = (SystemWebView) findViewById(R.id.cordovaWebView);
            CordovaWebView cordovaWebView = new CordovaWebViewImpl(new SystemWebViewEngine(webView));
            return cordovaWebView;
        }
    

      cordovaWebView对于xml里的SystemWebView 控件

       @Override
        protected void createViews() {
            if (preferences.contains("BackgroundColor")) {
                int backgroundColor = preferences.getInteger("BackgroundColor", Color.BLACK);
                // Background of activity:
                appView.getView().setBackgroundColor(backgroundColor);
            }
            appView.getView().requestFocusFromTouch();
        }
      
    

      

    5. 效果图

    
    
  • 相关阅读:
    团队建设
    风云变幻六十年 平板电脑演变史回顾
    在线ide汇总
    XAMPP中启动tomcat报错的解决方法
    ExtJs 中 xtype 与组件类的对应表
    FineReport关于Linux下字体乱码终极解决方案
    SqlDataReader的关闭问题
    MemberShip学习之:注册用户
    索引超出范围。必须为非负值并小于集合大小。
    利用SiteMapPath控件做论坛导航(也适合其它系统)
  • 原文地址:https://www.cnblogs.com/linlf03/p/7088821.html
Copyright © 2011-2022 走看看