已编辑 - 图片链接: http://tinypic.com/view.php?pic=4qir6v&s=6
我在webview中创建了一个简单的Web浏览器,如图所示。我能够通过点击网站或在文本栏中写入网址(GO按钮的左侧)来浏览网站,但是我无法在网页浏览中写入,即无法在搜索框中写入,如图中所示。
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10" >
<EditText
android:id="@+id/etURL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2" >
</EditText>
<Button
android:id="@+id/bGo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text="Go" >
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="8" >
<Button
android:id="@+id/bBack"
android:layout_width="115dp"
android:layout_height="wrap_content"
android:text="Back" >
</Button>
<Button
android:id="@+id/bForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forward" >
</Button>
<Button
android:id="@+id/bRefresh"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text="Refresh" >
</Button>
</LinearLayout>
<WebView
android:id="@+id/WebEngine"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="17.26" />
</LinearLayout>
答案 0 :(得分:0)
最后通过以下链接得到答案 http://code.google.com/p/android/issues/detail?id=7189
webview.requestFocus(View.FOCUS_DOWN);
webview.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;
}
});