0

How to Justify paragraph in textview setText option? I am loading data from API and need to display paragraph as justified.

textv.setText(Html.fromHtml(text)); I have tried below in adapter but nothing works text = text + ""+paragrph +"

";

Is it possible other than webview ?

Rajesh
  • 86
  • 12

2 Answers2

0

You cannot set the property like gravity in TextView. You can either use WebView or other open source libraries. Android does not support text justification yet.

AlphaQ
  • 656
  • 8
  • 18
0

You need to use WebView to justify text. Here is it an example:

    WebView webView = (WebView) findViewById(R.id.webView);
    webView .setBackgroundColor(Color.TRANSPARENT);
    String header = "<html><head><style type=\"text/css\">@font-face {font-family: MyFont;src: url(\"file:///android_asset/fonts/Walkway-Ultrabold.ttf\")}body {font-family: MyFont;font-size: medium;text-align: justify;}</style></head><body>";
    String footer = "</body></html>";
    String text_web_view = header + message + footer;
    webView.loadDataWithBaseURL(null, text_web_view, "text/html", "UTF-8", null);

This code set also a font placed into assets/fonts folder.

Marco Ferretti
  • 149
  • 1
  • 2
  • 12