So, you've created a project, launched it, familiarized yourself with the project structure, and Android Studio elements. You've learned the basic attributes for all views and even modified TextView. Let's delve into what TextView can do and how to modify it. Here are the main attributes of TextView that you can modify:
Basic attributes that exist for all views and containers:
And TextView-specific attributes:
Let's take our basic TextView:
<TextView
android:id="@+id/our_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Develop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
Which looks like this:
Disregard the app:layout_constraint parameters and sequentially add attributes:
android:textSize="32sp"
android:textColor="#0000FF"
android:textStyle="bold"
android:gravity
The main values for the gravity attribute are:
Multiple gravity parameters can be applied by listing them using the "|" symbol. For a more detailed understanding of how gravity works, we also need to set rigid dimensions and a background for TextView. It looks like this:
Set parameters:
android:layout_width="300dp"
android:layout_height="300dp"
android:gravity="center_vertical|end"
android:background="#D3A54A"
And it looks like this:
By using the background, we see the boundaries of our TextView. We also see that our text is vertically centered and aligned to the right.
android:lines and android:ellipsize
These two attributes work in tandem. Lines set how many lines TextView will render, and ellipsize defines the behavior for long text that won't fit. I'll use ellipsize="end," which automatically adds ellipses at the end of the text.
And it looks like this:
We've covered the basic attributes used in TextView. In the next lesson, we'll explore EditText - the element for text input from the keyboard.