Foreword: The return logic of our project request is, in Xwalkview inside all the page clicks the physical return key, will perform double repel the function, therefore, if your project request is not such, then this post does not have the big use to you, but may learn from each other ha.
Crosswalk's good, I don't have to repeat it here, than the performance of the original WebView not know how many times the upgrade, the original incompatible layout problem, in the crosswalk inside does not exist (because we use the project in the voice of the function, this feature in a Samsung mobile phone, Or have a problem), and so many benefits, of course, is not perfect, for example, if the problem, you can refer to the information is limited, we have to choose their own;
------------------------get to the point------------------------------
1, integration of crosswalk steps, I do not say, online a lot of, basically can integrate successful, is not very complex;
2, after the integration, you will find that performance has really increased more than a little bit, but if you click on the physical return key, you will find that he will not use you to write logic, and to perform the page's jump, which I think crosswalk do is very good, but as I said earlier, Our project requirements are no matter which page in the Xwalkview, double-click the physical return key have to exit, then there is a problem, generally we will go directly to onkeydown to write some logic, such as:
@Override Public
boolean onKeyDown (int keycode, keyevent event) {
if (keycode = = keyevent.keycode_back) {
// Double-Repel logical code return
true;
}
Return Super.onkeydown (KeyCode, event);
}
The above piece of code is the page, double-click Back to exit directly, but when testing you will find that the reality is not imagined, Xwalkview or will you press the return key to execute the jump to the previous page of the method, which is not what we want, so this method does not work;
3, the second method is a bit troublesome, rewrite the Xwalkview dispatchkeyevent method, judge if it is returned, directly shielded, this method is still more reliable, followed by the code:
A, you need a class that inherits from Xwalkview, named Myxwalkview.
Import android.app.Activity;
Import Android.content.Context;
Import Android.util.AttributeSet;
Import android.view.KeyEvent;
Import Org.xwalk.core.XWalkView;
public class Myxwalkview extends xwalkview{public
myxwalkview (context) {
super (context);
}
Public Myxwalkview (context, AttributeSet attrs) {
Super (context, attrs);
}
Public Myxwalkview {
Super (context, activity);
}
@Override Public
Boolean dispatchkeyevent (KeyEvent event) {
if event.getkeycode () = = Keyevent.keycode_back ) {return
false;
}
Return Super.dispatchkeyevent (event);
}
B and then in the place you use, replace the original xwalkview with the Myxwalkview absolute path, and change the class in the place you use it.
c, and then write in the OnKeyDown method in your mainactivity:
@Override Public
boolean onKeyDown (int keycode, keyevent event) {
if (keycode = = keyevent.keycode_back) {
Exitbydoubleclick ();
return true;
}
Return Super.onkeydown (KeyCode, event);
}
That's OK.