安卓PhoneGap与本地控件

5
我正在尝试使用PhoneGap构建Android应用程序。
我需要能够使用PhoneGap WebView(super.appView)及其所有的javascript魔力,但我还需要在WebView周围显示一些原生UI控件。
这篇文章提供了部分解决方案 Android PhoneGap Plugin, UI tabbar, resize WebView
有人成功地将PhoneGap与本地UI结合使用吗?
我还将使用GestureOverlayView,但那是另一个故事;)
3个回答

12

回答:

super.onCreate(savedInstanceState);
//creates super.appView and calls setContentView(root) in DroidGap.java
init();
//just an empty LinearLayout
layoutId = R.layout.blank;
view = new LinearLayout(this);
setContentView(layoutId);
view.addView(your_component_here);
view.addView((View) appView.getParent()); //adds the PhoneGap browser at index 1
//accesses the browser at index 1. Tells browser to not fill view
view.getChildAt(1).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));
setContentView(view);

我很难向你解释这个是如何工作的,我只能告诉你它确实有效,并且都是我自己完成的。

将视图设置为不同的颜色也有助于您了解正在发生的情况...

view.setBackgroundColor(Color.BLUE);

使用截至目前为止最新版本的PhoneGap-1.0.0.jar进行开发。


你能放一张屏幕截图展示结果吗? - hadi

8
更清晰的方法:
super.onCreate(savedInstanceState);

// Create native view with UI controls.
View header = View.inflate(getContext(), R.layout.header, null);

// PhoneGaps WebView is located inside a LinearLayout.
// The protected (and therefore inherited) variable root
// references this LinearLayout. Add your native Views
// to this variable.
root.addView(header);

// Create WebView and add it automatically to the LinearLayout.
super.loadUrl("file:///android_asset/www/index.html");

你也可以在 WebView 下面添加本地组件吗? - Edd
1
是的,在super.loadUrl("file:///android_asset/www/index.html");之后,只需添加另一个视图root.addView(footer);。 - Jan Laussmann
你使用的是哪个版本的PhoneGap? - Edd
目前Phonegap(Cordova)版本为1.5。但是计划更新到1.6版本。如果在1.6版本中无法使用此方法,我将更新我的帖子。 - Jan Laussmann
1
从Phonegap(Cordova)1.9版本开始,可以在本地应用程序中嵌入Cordova Webview组件。请参见http://docs.phonegap.com/en/edge/guide_cordova-webview_android.md.html#Embedding%20Cordova%20WebView%20on%20Android - Jan Laussmann

0

是的,您可以使用插件在HTML中嵌入本地控件。

使用插件从HTML页面调用包含本地视图的本地方法。

例如:window.plugins.anatomyPlugin.showAudio();

我用它来显示本地音频播放器设计。

PhoneGap的指南可能会有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接