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

Community
  • 1
  • 1
Hamid Reza
  • 624
  • 7
  • 23

4 Answers4

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);
        }
Javad Shirkhani
  • 343
  • 6
  • 11
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.

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);
ismail alaoui
  • 5,748
  • 2
  • 21
  • 38
-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.

rusted brain
  • 1,052
  • 10
  • 23