【发布时间】:2016-03-10 13:09:17
【问题描述】:
大家好,我是科尔多瓦的新手,我在我的 ionic 应用程序中集成了 webview,所以下面是我的代码
Hello.java
public class Hello extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
if (action.equals("greet")) {
Context context = cordova.getActivity().getApplicationContext();
Intent intent = new Intent(context,Main.class);
cordova.startActivityForResult((CordovaPlugin)this,intent,100);
callbackContext.success();
return true;
} else {
return false;
}
}
}
Main.java
public class Main extends CordovaActivity {
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_webview);
mWebView = (WebView) findViewById(R.id.web_view);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDisplayZoomControls(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.requestFocus(View.FOCUS_DOWN);
mWebView.loadUrl("https://www.google.co.in/");
}
}
编辑 layout_webview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:descendantFocusability = "blocksDescendants"
android:orientation="vertical"
android:layout_height="match_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
/>
</LinearLayout>
当我在上面运行代码时,我无法在我的 web 视图中专注于谷歌搜索 edittext,所以知道如何解决这个问题吗?你的所有建议都很有价值
编辑 2
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDisplayZoomControls(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.requestFocus(View.FOCUS_DOWN | View.FOCUS_UP);
mWebView.getSettings().setLightTouchEnabled(true);
mWebView.requestFocus();
mWebView.loadUrl("https://www.google.co.in/");
编辑 3
mWebView = (WebView) findViewById(R.id.web_view);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDisplayZoomControls(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setLightTouchEnabled(true);
mWebView.requestFocus();
mWebView.loadUrl("https://www.google.co.in/");
mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
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;
}
});
【问题讨论】:
-
jaydroider:检查我的问题中的编辑部分
标签: android cordova webview ionic-framework