Android Fragment可以覆盖PhoneGap活动吗?

con*_*ile 7 java android cordova

以下图像应代表以蓝色标记的PhoneGap/Cordova应用程序.红色区域应该是Android片段.

在此输入图像描述

是否有可能覆盖PhoneGap活动的Android片段?

编辑:重叠的Android片段应该像图像处理这样的任务.如何编写与Fragment通信的PhoneGap插件?

pel*_*lus 7

我这样做的方法是编写一个插件,显示一个没有边框,背景阴影等的自定义对话框.

我的execute()方法如下所示:

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (resources == null)
            resources = cordova.getActivity().getApplication().getResources();
        if (package_name == null)
            package_name = cordova.getActivity().getApplication().getPackageName();
        if (inflator == null) {
            inflator = cordova.getActivity().getLayoutInflater();
        }

        if (action.equals("show")) {
            this.show(args, callbackContext);
            return true;
        }

        return false;  // Returning false results in a "MethodNotFound" error.
}
Run Code Online (Sandbox Code Playgroud)

并且show()方法包含这样的内容:

[...]
    Runnable runnable = new Runnable() {
        public void run() {
            pinpad = new Dialog(cordova.getActivity());
            pinpad.requestWindowFeature(Window.FEATURE_NO_TITLE);
            Window window = pinpad.getWindow();
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            WindowManager.LayoutParams wlp = window.getAttributes();
            wlp.gravity = Gravity.BOTTOM;
            window.setAttributes(wlp);

            pinpad.setCancelable(false);
            pinpad.setContentView(view);
            pinpad.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) height);
            pinpad.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
[...]
Run Code Online (Sandbox Code Playgroud)

如果您的窗口(红色部分)必须放置在某个特定位置(不在屏幕的中心或底部),那么您必须将坐标从javascript传递到本机插件.

  • 此代码显示在phonegap应用程序之上的本机android对话框.如果我弄错了,这就是你想要的?该怎么办?你必须创建一个phonegap插件并从js调用它.然后插件whill在你的phonegap应用程序顶部显示一个对话框. (2认同)