我正在研究webview
。如果我點擊我的webview
中的任何內容,則會使用webviewclient
類重定向到另一個鏈接。在android中用於webview的後退和前進按鈕。怎麼樣?
現在我把一個頁腳包含back
和forward
按鈕,來做普通瀏覽器中的功能。
我可以工作到back
和forward
的webview
。它工作正常。
現在我想在頁腳中設置一個按鈕,最初應該沒有集中注意力,它應該可以點擊並且不能動態點擊。
我正在研究webview
。如果我點擊我的webview
中的任何內容,則會使用webviewclient
類重定向到另一個鏈接。在android中用於webview的後退和前進按鈕。怎麼樣?
現在我把一個頁腳包含back
和forward
按鈕,來做普通瀏覽器中的功能。
我可以工作到back
和forward
的webview
。它工作正常。
現在我想在頁腳中設置一個按鈕,最初應該沒有集中注意力,它應該可以點擊並且不能動態點擊。
我使用canGoBack()
和canGoforward()
解決了這個問題,我們可以使用obj_name.setEnabled(false);
來禁用這些按鈕。
如果你的佈局像
<?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/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:enabled="false"
android:text="Back"/>
<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" />
現在,我們可以實現這樣的...
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
//Web View Initialization
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
//Button Initialization
final Button backButton =(Button) findViewById(R.id.backButton);
final Button forwardButton =(Button) findViewById(R.id.forwardButton);
//Back Button Action
backButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Going back if canGoBack true
if(webView.canGoBack()){
webView.goBack();
}
}
});
//Forward Button Action
forwardButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Go Forward if canGoForward is frue
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);
//Make Enable or Disable buttons
backButton.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("www.google.com");//Your url goes hare
你一直刪除並重新添加了同樣的問題。也許你應該改寫這個問題。有人可能會有理由不回答你的問題。就我而言,我完全不知道最後一句話的含義。 – CommonsWare 2010-02-23 12:48:20
當webview加載時,沒有向前(canGoForward())或向後(canGoBack())選項,不是嗎?那麼我想設置這些按鈕不應該focusable或可點擊。那是所有的朋友。 – Praveen 2010-02-23 16:59:09