1. In the main.xml file, and add the below code below your layout tags. This will display a button.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="My Button Text"
/>
</LinearLayout>
2. Compile and run!
3. This will display a button, however nothing will happen when you click on the button yet though! To do that you'll need to add an onClick to your button.
Next Recommended Article: Add an onClick to a Button
Related Articles
- Problem: Widgets are not displayed at run-time
- Set the Text Color to a Button
- Create an Intent to Open a new Activity/Screen
- Set/Change the Height of a Button
- Set Font Size of a Button