我们在webview里面使用javascript处理按键遇到了焦点问题,于是google,发现了stackoverflow里面的答案,http://stackoverflow.com/questions/19716840/handle-arrow-keys-from-d-pad-on-webview-google-tv-app。
于是从https://code.google.com/archive/p/googletv-android-samples/source/default/source这里下载了代码。
我把http-client的js代码拷贝到了本地的assets目录,发现焦点仍然不起作用。于是跟到了js代码,发现了如下代码
IndexPage.prototype.setUpKeyHandling = function () {
if(this.isEmbedded()) {
// We want the native app to access this
window.androidKeyHandler = new AndroidKeyHandler(this.getFocusController());
}
};
原来这里有限制,于是我修改了代码,发现可用。
IndexPage.prototype.setUpKeyHandling = function () {
// if(this.isEmbedded()) {
// We want the native app to access this
window.androidKeyHandler = new AndroidKeyHandler(this.getFocusController());
// }
};
具体工程代码可以从这里下载,在Android Studio测试有效。