Multiple CordovaWebViews in one Android activity?

CordovaWebView was introduced in cordova 1.9. http://docs.phonegap.com/en/2.0.0/guide_cordova-webview_android.md.html

Has anyone tried to host multiple web views in one action? will this work? recommended?

+4
source share
1 answer

It is doable. The cordova pointer gives some hint.

Also suppose MyActivity extends DriodGap, then you need

1) override init() method

2) resize the first (original view) so that it does not occupy the entire screen

 this.appView.setLayoutParams(new LinearLayout.LayoutParams( [desired width], [desired height], )); 

3) Create a new CordovaWebView, set its LayoutParams, similar to the first. Then add it to root mode:

 this.root.addView(cwv2); 

4) Two web views should be displayed now. But if there are inputs in two views, you will find that there is focus on both inputs.

5) To get rid of the dual focus problem, paste the following code:

 this.appView.requestFocus(View.FOCUS_DOWN); this.appView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); 
0
source

Source: https://habr.com/ru/post/1433855/


All Articles