Android 尝试将导航添加到Webview
我正在尝试将导航添加到我的Android 尝试将导航添加到Webview,android,android-webview,android-button,Android,Android Webview,Android Button,我正在尝试将导航添加到我的WebView,但只有一个按钮可用,而其他按钮不可用 以下是我的单击侦听器方法: @Override public void onClick(View v) { switch (v.getId()) { case R.id.go_btn: String theWebsite = URL.getText().toString(); ourbrowser.loadUrl(theWebsite);
WebView
,但只有一个按钮可用,而其他按钮不可用
以下是我的单击侦听器方法:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.go_btn:
String theWebsite = URL.getText().toString();
ourbrowser.loadUrl(theWebsite);
break;
case R.id.forwardbutton:
if (ourbrowser.canGoForward()) ;
ourbrowser.goForward();
break;
case R.id.rfbutton:
ourbrowser.reload();
break;
下面是我的按钮XML代码:
<Button
android:id="@+id/go_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/go_btn"
android:background="#bdbdbd"
android:textColor="#000000"
android:layout_gravity="right"
android:imeOptions="actionGo"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/rfbutton"
android:layout_toEndOf="@+id/rfbutton"
android:layout_marginLeft="16dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/go_rf"
android:id="@+id/rfbutton"
android:background="#bdbdbd"
android:textColor="#000000"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/forwardbutton"
android:layout_toEndOf="@+id/forwardbutton"
android:layout_marginLeft="16dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/go_frw"
android:id="@+id/forwardbutton"
android:background="#bdbdbd"
android:textColor="#000000"
android:layout_alignTop="@+id/rfbutton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp" />
所以我有Go、Forward和Refresh按钮,但出于某种原因,只有Go按钮起作用
请帮帮我 我的建议是在web视图中添加一个侦听器,以便您知道网页何时完成加载。加载后,启用后退和前进按钮 使用webview.setWebViewClient覆盖:
@Override
public void onPageFinished(WebView view, String url) {
toggleURLButtons(view.canGoBack(), view.canGoForward());
}
private void toggleURLButtons(boolean canGoBack, boolean canGoForward) {
mGoBackwardButton.setAlpha(canGoBack == true ? 1: 0.25f);
mGoBackwardButton.setEnabled(canGoBack);
mGoForwardButton.setAlpha(canGoForward == true ? 1: 0.25f);
mGoForwardButton.setEnabled(canGoForward);
}
然后单击按钮时,按钮应该可以工作。请发布按钮代码(布局XML),我在下面发布了。也许你可以帮我。还有一个问题:请在你的主要活动中发布你的onCreate,在那里你可以初始化你的东西。另外,请使用问题标签下的编辑链接并将其添加到那里,而不是将其添加为答案。如果您收到的错误消息是代码太多,请尝试添加更多的文本。Arved:您是否也可以将代码发布到为按钮分配事件侦听器的位置?