一个Android Fragment能覆盖PhoneGap Activity吗? [英] Can an Android Fragment overlaying the PhoneGap Activity?

查看:339
本文介绍了一个Android Fragment能覆盖PhoneGap Activity吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下图片代表以蓝色标示的PhoneGap / Cordova应用程式。
红色区域应该是一个Android Fragment。

The following image should represent an PhoneGap/Cordova app which is marked in blue. The red area should be an Android Fragment.

是否可能有一个Android Fragment覆盖了PhoneGap活动?

编辑: Android Fragment应该像图像处理任务。
我如何编写一个PhoneGap插件与Fragment通信?

The overlaying Android Fragment should the tasks like image manipulation. How do I have to write a PhoneGap plugin that communicates with the Fragment?

推荐答案

通过编写一个插件,显示一个自定义对话框,无边框,背景阴影等。

the way i did this was by writing a plugin that shows a custom dialog without border, background shadow, etc.

我的execute()方法如下:

my execute() method looks like this:

@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.
}

并且show()方法包含以下内容:

and the show() method contains something like this:

[...]
    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);
[...]



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

if your window (the red part) has to be placed in some particular position (not in the center or at the bottom of the screen) then you have to pass coordinates from javascript to native plugin.

这篇关于一个Android Fragment能覆盖PhoneGap Activity吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆