Justifying text of TextView helps you to represent your textual contents in a better way to users. The text alignment on both left and right side makes paragraphs align with other elements and screen bezels.
Kotlin Android TextView – Justify Text
There are two method to justify your Text View which are given below:
METHOD 1:
|
Justify text in TextView with Key Attribute “inter-word”
|
In this method, we will tell you that how you can justify any text in seconds by using attribute key value “INTER_WORD”. This is built in feature provided by Android Studio version 3 or above.
Here look into following example where we present with how to justify text in TextView through layout file and programmatically by using “inter_word”.
To justify text in TextView through layout file, add the following attribute key : value ( android:justificationMode="inter_word") to the TextView.
<TextView
android:id="@+id/tvJustified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:justificationMode="inter_word"
android:text="The text in this TextView is justified." />
|
After using this simple attribute you see that your whole text within the textview will be justify, See the Picture [1] below.
Justified Text |
Non-Justified Text |
Note: This feature is available from Android 8.0 or above only.
METHOD 2:
|
Justify text in TextView by Using External Library
|
There is another method to justify text in TextView that is a use of external libraries.
Here are given two libraries you can add anyone of them
1- implementation 'me.biubiubiu.justifytext:library:1.1'
2- implementation 'com.github.bluejamesbond:textjustify-android:2.1.6'
How to Implement External Library in Android Studio
Steps involved to implementing these libraries in to android studio.
Ø
Go to Just Build.gradle (Module: App)
Ø Paste library anyone library compile code below the
dependencies {
//your library code here
}
Information
|
In my case I will implement 'me.biubiubiu.justifytext:library:1.1'
to justify the text in TextView
|
Ø Now Click on “Sync” to add these libraries in to android studio. That’s it you have done this.
Justifying Text using External Libraries.
Now go to any activity.xml file where you want to justify text and replace word TextView with me.biubiubiu.justifytext.library.JustifyTextView as seen in below code.
<me.biubiubiu.justifytext.library.JustifyTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="This is justified text by using External Library.
/>
That’s it. we have done. It
|
3 Comments
Not work it. when i use it then crash my apps.
ReplyDeleteShet ، no arabic text suport !!!!
ReplyDeleteThis is very useful information. Thank you!
ReplyDeleteThis helped me solve my problem