𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼
Hello dear mates, I hope you all are well. Today we are going to learn an amazing widget TextInoutLayout. It may not appear in your XML file but you need to download the dependency by simply following the first step in the procedure.
GitHub Link
Use this GitHub project to clone into your directory. It will always get updated in the next lecture. So that you will never miss the latest code. Happy Coding!.
What Should I Learn
- How to download TextInputLayout
- How to use TextInputLayout
Assignment
- Download and Add TextInputLayout to your activity
- Change the input type to password
Procedure
First, we need to download the TextInoutLayout. Simply follow this mockup and an internet connection is required to download it.
It will ask for permission to add the dependency click on Ok to add the material library to our project. The Gradle build will start and wait until it is complete.
Now add the TextInputLayout and move the EditText inside the TextInputLayout Tag, Like this.
This InputLayout help us to get the floating hint that will always appear on the EdiText in a stylish animation. We can allow add border and password show/hide function and a lot more. Now we can move the hint in the InoutLayout tag.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Mobile Number">
For passwords, we can use this code to enable the hide and show function.
app:passwordToggleEnabled="true"
Here is the main_activity.xml
code, You can also get the lecture 6 updates on the Github.
<?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" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
app:passwordToggleEnabled="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:text="+923451111111"
android:textColor="@color/black"
android:textColorHint="@color/purple_200"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>