Android Justify spanable Text-view that support RTL Languages
Asked Answered
A

4

16

I need to create a custom text-view in android, first of all it should be justified, then it should support spans and although it should support RTL (Right to Left) languages for ex: Farsi (Persian) ,...

I'm working on this issue for a week! but In fact I stuck In a bad condition because non of available libraries support all these conditions ( Justify, Spanable, RTL)

Do you have any idea?!


I although checked lots of libraries for ex: Link

Arrear answered 28/7, 2015 at 11:34 Comment(5)
I have same problem too!Tibold
Attribute "android:textDirection" is available but can be only used in API level 17 or above.Here is the linkAlthough
Hi Hamid - try it : github.com/Saleh-Hassan/RTL-TextJustify-AndroidFertilize
Hi Saeid - this library does not support SpanArrear
for span check my answerStreetcar
S
1

This code worked for my rtl textView :

         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            textView.setJustificationMode(LineBreaker.JUSTIFICATION_MODE_INTER_WORD);
        }else {
            textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
            textView.setGravity(Gravity.CENTER_HORIZONTAL);
        }
Sherlene answered 4/7, 2021 at 7:59 Comment(0)
H
0

You may be able to use this.

The package was created specifically for Right-ToLeft and Justified Textviews, and should support Spannable since it is an extension of TextView.

Hartal answered 13/8, 2015 at 21:54 Comment(0)
S
0

how to justify span RTL TextView ?

First use this library RTL-TextJustify-Android

Then before setting text to the TextView :

 TextViewEx = myJustifiedTextView;
 myJustifiedTextView = findViewById...........;


 finalDescription = "";

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        finalDescription = Html.fromHtml(SpanTextHere, Html.FROM_HTML_MODE_COMPACT).toString();
    } else {
        finalDescription = Html.fromHtml(SpanTextHere).toString();
    }

myJustifiedTextView.setText(finalDescription,true);
Streetcar answered 21/11, 2019 at 13:40 Comment(0)
O
-1

Try adding android:supportsRtl="true" to the <application> element in your manifest file and change your apps "left/right" layout properties to new "start/end".

Refer this link for more information.

Overstay answered 20/8, 2015 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.