2010-02-23 15 views
5

मैं webview पर काम कर रहा हूं। अगर मैं अपने webview में कुछ भी क्लिक करता हूं, तो यह webviewclient कक्षा का उपयोग कर किसी अन्य लिंक पर रीडायरेक्ट करता है।पीछे और आगे बटन। कैसे?

अब मैं सामान्य ब्राउज़र में कार्यक्षमता करने के लिए एक पाद लेख back और forward बटन डालता हूं।

मैं back और forwardwebview के बारे में काम कर सकता हूं। यह बढ़िया काम करता है।

अब मैं पाद लेख में एक बटन सेट करना चाहता हूं, शुरुआत में ध्यान केंद्रित नहीं किया जाना चाहिए और इसे क्लिक करने योग्य और गतिशील रूप से क्लिक करने योग्य नहीं होना चाहिए।

+1

आप को हटाने और रखने वही सवाल फिर से जोड़ रहे हैं । शायद आपको सवाल फिर से लिखना चाहिए। ऐसे कई कारण हो सकते हैं कि लोग आपके प्रश्न का उत्तर क्यों नहीं दे रहे हैं। मैं, एक के लिए, बिल्कुल नहीं पता कि अंतिम वाक्य का क्या अर्थ है। – CommonsWare

+0

जब वेबव्यू आंशिक रूप से लोड होता है तो कोई आगे नहीं है (canGoForward()) या पिछड़ा (canGoBack()) विकल्प, है ना? तो मैं उन बटनों को सेट करना चाहता हूं जो फोकस करने योग्य या क्लिक करने योग्य नहीं हैं। वह सब दोस्त है। – Praveen

उत्तर

7

मैंने canGoBack() और canGoforward() का उपयोग करके इस समस्या को हल किया, हम obj_name.setEnabled(false); का उपयोग करके उन बटन को अक्षम कर सकते हैं।

Here's a good sample from Google's, worth looking at.

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 
संबंधित मुद्दे