2010-02-23 3 views
5

나는 webview에서 일하고 있습니다. 내 webview에서 아무 것도 클릭하면 webviewclient 클래스를 사용하여 다른 링크로 리디렉션됩니다.android의 webview 용 앞뒤 단추. 방법?

일반 바닥 글에 backforward 버튼이 포함 된 바닥 글을 붙였습니다.

backforwardwebview으로 사용할 수 있습니다. 그것은 잘 작동합니다.

이제 꼬리말에 버튼을 설정하고 싶습니다. 처음에는 집중하지 않아야하며 클릭 할 수 있고 동적으로 클릭 할 수 없게 작동해야합니다.

+1

같은 질문을 다시는-추가하는 경우 . 아마도 당신은 질문을 다시 써야합니다. 사람들이 귀하의 질문에 답변하지 않는 이유가있을 수 있습니다. 나는 마지막 문장이 무엇을 의미하는지 전혀 모른다. – CommonsWare

+0

webview가 처음으로로드 될 때 앞으로 (canGoForward()) 또는 뒤로 (canGoBack()) 옵션이 없습니까? 그때 나는 그 버튼들이 focusable하거나 clickable하지 않아야한다. 모든 친구. – Praveen

답변

0

<?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