Android App Development | Beginner Course | Lecture#2 | Hive Learners

Words
375
Reading
2 min
4y
Listen to this post
~3 min

饾摉饾摶饾摦饾摦饾摻饾摬饾摲饾摪饾摷

Hello dear Hive Learners, I know it's a delay in the Android Development series. But I was sick and not able to write some code in the hot summer. So I am here again with a new topic Button. Today we will learn how to draw a button on the screen using XML. I hope you will enjoy it and get it interesting.

multi_purpose

What Should I Learn

  • What LinearLayout
  • How to draw a Simple Button

Assignment

  • Draw a simple Button and write your Hive username to it.

First of all, where we leave in the first lecture just click on the split button as shown here it will show us the design and the code behind it and show us the live changes.

image

Here s the code you need to replace your main_activity.xml code top this so that you can also become a noob coder like me 馃槈.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hive Learners Start Buton"

        />
</LinearLayout>

image

Lets read the first line
<?xml version="1.0" encoding="utf-8"?>
it is just a XML header file and it is necessary and don't change anything in it.

<LinearLayout
The word itself says that it is a Layout and Linear too. It is a container where we hang our T-Shirts and Old Jackets 馃榿. We use this container to add more layouts and widgets in it.

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

Their lines are again no need to change and they always lie in the first layout.

Then we see the height and width of this container. match_parent is a code word that tells the layout of the stretch out in the available space on the mobile screen.

Orientation means how the other layout is ordered in this LinearLayour. I set it verticle so that every layout inside it becomes in verticle order. In the context line, I add the activity name where is attached and there we will write JAVA code for it.

 android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"

Here is the code for Button. B is in a capital note that every built-in layout starts with a capital letter. I add height and width to wrap_content. It means that the Button will not stretch completely but it stretches according to the words in it.
As I set the text to Hive Learners Start Button. Draw your button onscreen and we will learn other colorful properties tomorrow. Thank You

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hive Learners Start Buton"

        />

hl_divider.png

Thank You

hl_footer_banner.png

Android App Development | Beginner Course | Lecture#2 | Hive Learne... | Ecency