`
longgangbai
  • 浏览: 7251273 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

phonegap底层原理学习和研究(四)

 
阅读更多

         在phonegap的android开发中主要通过WebView显示相关的本地页面。针对WebView设置的代码如下:


       //创建相关的Web容器
        this.appView = new WebView(DroidGap.this);
        this.appView.setId(100);
        //设置WebView的布局
        this.appView.setLayoutParams(new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT,
                1.0F));
      //获取WebView的WebSetting的几个方法以便于后面通过反射注入相关的存储
        WebViewReflect.checkCompatibility();
     
        this.appView.setWebChromeClient(new GapClient(DroidGap.this));
        this.setWebViewClient(this.appView, new GapViewClient(this));

        this.appView.setInitialScale(100);
        this.appView.setVerticalScrollBarEnabled(false);
        this.appView.requestFocusFromTouch();

        // Enable JavaScript
        WebSettings settings = this.appView.getSettings();

       //启用js脚本的运行
        settings.setJavaScriptEnabled(true);
        //js是否可以打开窗体

        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

        // Enable database
        settings.setDatabaseEnabled(true);
        String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
        settings.setDatabasePath(databasePath);

        // Enable DOM storage
        WebViewReflect.setDomStorage(settings);
       
        // Enable built-in geolocation
        WebViewReflect.setGeolocationEnabled(settings, true);

        // Create callback server and plugin manager
        this.callbackServer = new CallbackServer();
        this.pluginManager = new PluginManager(this.appView, this);       

        // Add web view but make it invisible while loading URL
        this.appView.setVisibility(View.INVISIBLE);
        root.addView(this.appView);

分享到:
评论
1 楼 zhiduo5 2012-09-08  
我有个问题啊,就是想实现super.loadUrl();时等页面加载成功在显示,不用开场动话那种,求代码,请多指点!

相关推荐

Global site tag (gtag.js) - Google Analytics