Mega Code Archive

 
Categories / Android / UI
 

Load image from remote host to WebView

package app.test; import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; public class Test extends Activity {     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);                          WebView wv = (WebView) findViewById(R.id.webview1);                   wv.setWebViewClient(new Callback());         WebSettings webSettings = wv.getSettings();         webSettings.setBuiltInZoomControls(true);         wv.loadUrl("http://yourHost.com/1.jpg");                      }          private class Callback extends WebViewClient {       @Override     public boolean shouldOverrideUrlLoading(WebView view, String url) {       return(false);     }   }   } //main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     > <WebView android:id="@+id/webview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content" />      </LinearLayout>