In Android, just use “android.widget.Button” class to display a normal button.

In this tutorial, we show you how to display a normal button, add a click listener, when user click on the button, open an URL in your Android’s internet browser.

P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3.

For more advance function, like image, please refer to this ImageButton example and also this ImageButton selector example.

1. Add Button

Open “res/layout/main.xml” file, add a button.

File : res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >
        android:text="Button - Go to" />

2. Code Code

Attach a click listener to the button.

When user click on it, open mobile browser and display URL :

File :

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MyAndroidAppActivity extends Activity {
	Button button;
	public void onCreate(Bundle savedInstanceState) {
	public void addListenerOnButton() {
		button = (Button) findViewById(;
		button.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
			  Intent browserIntent = 
                            new Intent(Intent.ACTION_VIEW, Uri.parse(""));

3. Demo

Run the application.

1. Result, a normal button.

android button demo1

2. Click on the button, display URL in browser.

android button demo2

Download Source Code

Download it – (15 KB)


  1. Android Button JavaDoc
Tags :
Founder of, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.
My website is hosted by Liquid Web, I really like their fast and helpful support, it saved me a lot of time. Furthermore, their servers are extremely reliable, fast and stable, I don't remember when was the last time we had server downtime. Btw, they're offering $100 Coupon now, if you are sourcing for great hosting provider, go grab it.

Related Posts

Popular Posts