Spiga

5min Android Hack #3: Catch URLs in WebView

How to intercept loading URLs inside your WebView.

  • Let's assume you have a WebView available in your activity, like this:
    mWebView = (WebView) findViewById( R.id.mywebview);

  • Now you can override the shouldOverrideUrlLoading method like this:
    mWebView.setWebViewClient(new WebViewClient(){
    @Override public boolean shouldOverrideUrlLoading(WebView view,
    String url)
    {
    ...
  • That's it. Each time a link is clicked on your WebView, it will call your shouldOverrideUrlLoading method. The method should return true if the URL was acted upon, or false otherwise.
More Information: Android Hello, WebView Tutorial.

Digg Technorati del.icio.us Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy

5min Android Hack #2: Remove Title Bar

How to remove the title bar of an Activiy.

  • In the onCreate method of the Activity, add
    requestWindowFeature(Window.FEATURE_NO_TITLE);

More Information: Android Developer - Activity Reference

Digg Technorati del.icio.us Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy

5min Android Hack #1: Set Background Image

How to set a background image on a view on Android.

  • Add an image, preferably a PNG, to the "res/drawable" folder.
  • Open the XML file for the respective UI component, and add this to the element you want to set the background image for:
    android:background="@drawable/<your image>
    You can omit the file extension. The @drawable part in the reference to the image tells Android to take the image from your res/drawable folder.
More information: Android Developer - Declaring Layout

Digg Technorati del.icio.us Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy