Android Button Example Code

In this tutorial, we are going to learn about button in android i.e. How to display a normal button and to add a click listener, when user clicks on the button, an URL opens a webpage?
Submitted by Shamikh Faraz, on April 28, 2018

1) XML File: activity_main

<?xmlversion="1.0"encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.faraz.button_example.MainActivity"tools:layout_editor_absoluteY="81dp"><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Go to includehelp.com"tools:layout_editor_absoluteX="110dp"tools:layout_editor_absoluteY="215dp"/></android.support.constraint.ConstraintLayout>