Android App Development | Beginner Course | Lecture#3 | Hive Learners
饾摉饾摶饾摦饾摦饾摻饾摬饾摲饾摪饾摷
Hello Hive Learner, In this lecture, we will add some colors to the widgets in showing on the screen. We will learn how to give a unique name to any widget layout. It is a very important part of today's lecture.
What Should I Learn
- How to set Text Color
- How to add Background Color
- What is id
- How to set the id
Assignment
- Fill your favorite color in the Button
- set a unique id for the first LinearLayout
Procedure
We start where we left in our second tutorial, Two new Lines were added to the code that I highlight in their screenshot.
android:textColor="@color/white"
android:backgroundTint="@color/purple_200"
textColor is used to set the color of the text that is showing in the Button. We can also use hex code for the like for black color we can use this code, It will change the text color to black as #000000 is the hex code for black color.
android:textColor="#000000"
We can always select a custom color by clicking the color shown on the side of the code line and opening the Custom tab as shown in this screenshot
The same explanation for the backgroundTint. But this time the color below the Text changes. We also change the background color with hex code or set use the Custom tab to pick the hex code visually.
android:backgroundTint="@color/purple_200"
Now we set an id of the Button. It is the unique name in the same file. The same file not allowed the duplicate id for any widget. Setting id means it is a newborn child and you give him a unique name that is suitable for it.
android:id="@+id/start_btn"
All the code is here that we write today. You must give it a try and use different colors for practice. The comment section is always open.
<?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:id="@+id/start_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#3F51B5"
android:text="Hive Learners Start Button Colored"
android:textColor="#FFEB3B" />
</LinearLayout>