Android App Development | Beginner Course | Lecture#4 | Hive Learners
饾摉饾摶饾摦饾摦饾摻饾摬饾摲饾摪饾摷
Hi Hive Learners member, I hope you all are well and learning something new in Android Development. I am also hoping that you complete the assignment of lecture 1, 2 and 3. Today we will learn a new widget TextView. So keep your focus on this lecture and learn an interesting new widget.
What Should I Learn
- What is TextView
- How to set the font family
- How to set the text size
- How to style the text
Assignment
- Add TextView to your design activity
- Write your Hive username in it in bold style
- Change the font family of it and size.
Procedure
We start from where we left in Lecture 3. We add a new widget TextView with the wrap_content height and width. I set my Hive username as text in it.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="faisalamin"
/>
Then I style the text by this line. I use italic and bold as the concatenation sign (pipe sign) |. You can use only italic or bold also without a pipe sign.
android:textStyle="italic|bold"
I change the text size by adding this line. You can use any suitable size with the postfix sp. It will automatically change the text's size in TextView and adjust the height and width.
android:textSize="16sp"
Now I change the font family and color of the text. Some sen-serif fonts are built-in and we can use them easily. We can add custom fonts to our project but we will learn it in the coming lectures. So here is the final code of TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-smallcaps"
android:text="faisalamin"
android:textColor="@color/teal_700"
android:textSize="16sp"
android:textStyle="italic|bold" />
Here is the full activity_main.xml code
<?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" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-smallcaps"
android:text="faisalamin"
android:textColor="@color/teal_700"
android:textSize="16sp"
android:textStyle="italic|bold" />
</LinearLayout>
Thank You