我想知道如何像在android的私人浏览器中一样禁用和启用前向菜单按钮.我正在编写一个显示3个webview的应用程序,并且我希望合并android自己的浏览器选项的基本功能.到目前为止一切正常wrt功能.唯一的事情是“ forward”菜单项始终处于启用状态.我也提到过conditoin,因为canGoFwd然后goFwd.问题是,我分别定义了菜单项并分别编写了前进功能,问题是动态更改“前进”按钮的状态
解决方法:
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
final Button prevIoUsButton =(Button) findViewById(R.id.prevIoUsButton);
prevIoUsButton.setonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Todo Auto-generated method stub
if(webView.canGoBack()){
webView.goBack();
}
}
});
final Button forwardButton =(Button) findViewById(R.id.forwardButton);
forwardButton.setonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Todo Auto-generated method stub
if(webView.canGoForward()){
webView.goForward();
}
}
});
webView.setWebViewClient( new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// Todo Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished( WebView view, String url ) {
super.onPageFinished(webView, url );
prevIoUsButton.setEnabled(view.canGoBack());
forwardButton.setEnabled(view.canGoForward());
}
@Override
public void onReceivedError( WebView view, int errorCode, String description, String failingUrl ) {
super.onReceivedError( webView, errorCode, description, failingUrl );
Toast.makeText( WebViewActivity.this, description, Toast.LENGTH_LONG );
}
} );
webView.loadUrl("");
webview.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="@+id/prevIoUsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:enabled="false"
android:text="prevIoUs"/>
<Button
android:id="@+id/forwardButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/prevIoUsButton"
android:text="forward"
android:enabled="false" />
</RelativeLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。