0

So I am currently developing an app on Android Studio using Java and XML. I read in this post that we can justify the text in a TextView section by using the following property:

android:justificationMode="inter_word"

However, for some unknown reason this does not seem to work when deployed on my device. I tried checking if it also happens on AVDs and it does not, nor does it happen on the design canvas, in which also appears justified. So it works in AVDs and design canvas but doesn't work on 2 different actual mobile phones. I have also tried to change the text justification through Java but it seems to ignore the textView.setJustificationMode(JUSTIFICATION_MODE_INTER_WORD);

Is this a problem related to the build.gradle? Please, let me know if you guys have any idea on what might be causing this issue. Thanks!

Ps: Android Phone Versions: 12 and 8; Android Studio Version: Android Studio Chipmunk | 2021.2.1 Patch 2

Ps2: Below follows an XML file used in the app.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:justificationMode="inter_word"
            android:textColor="@color/black"
            android:textSize="15sp"
            android:layout_marginTop="5dp"
            android:padding="4dp"
            android:text="Donec mollis varius ullamcorper. Curabitur blandit nisl sapien, gravida pellentesque metus hendrerit non. Vivamus vitae faucibus dolor. Etiam sit amet hendrerit nulla. Ut blandit eu mi quis ultrices. Proin ut quam quis neque efficitur ultrices. Duis ut laoreet libero. Curabitur lacinia ligula augue, sed ornare elit tempor vel. Sed bibendum scelerisque suscipit. Donec metus neque, tincidunt a urna aliquet, sodales sodales felis. Nullam ultricies neque vel lorem cursus, eget dapibus massa condimentum. Praesent rhoncus dolor tortor, non sodales ante mattis id. Sed accumsan porta eleifend. "/>

    </RelativeLayout>


</RelativeLayout>

This is the result in the design canvas (and AVDs):

enter image description here

And this is the result in the actual mobile phone:

enter image description here

Blue Ross
  • 69
  • 6
  • 1
    Your gradle file isn't going to help at all, it has nothing to do with text justification. Your xml file might help. – Gabe Sechan Sep 06 '22 at 04:25
  • Thanks for the feedback! I've updated the post with an XML file used in the app. However, it is worth mentioning that this issue happens in all TextViews on all XML files used throught the app. Thanks again! – Blue Ross Sep 06 '22 at 15:19

1 Answers1

1

justificationMode is only supported for api level 26 and higher to achieve justification in TextView use following method

method 1 : change minSdk to 26 from gradle file but older divices cant support this ie api less than 26

defaultConfig {
    applicationId "com.example.my_app"
    minSdk 26
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

method 2 : if you need to support older Android versions, JustifiedTextView is what you need . use this dependence before using JustifiedTextView

implementation 'com.codesgood:justifiedtextview:1.1.0'

<com.codesgood.views.JustifiedTextView
    android:id="@+id/tv_justified_paragraph"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="@string/lorem_ipsum_extended"
    android:textColor="@android:color/black"
    android:textSize="15sp" />

It worked in my case hope it work well in yours . refer this