Justify Text in Android

27 sec read

Dear Friends

Lets brainstorm and find out a solution.

Problem : Android doesn’t support text justification alignment directly when it comes to aligning text in Textview.

what to do?

We I encountered this problem i google net regarding this and found in many blogs that this problem can be solved by using a WebView.

So I decided to develop a custom component extending a webview.

 

public class JustiFiedTV extends WebView {

    public JustiFiedTV(Context context) {
        super(context);
        this.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    }


    public JustiFiedTV(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setBackgroundColor(getResources().getColor(android.R.color.transparent));
    }

    public void setText(String data) {
        this.loadData(data,"text/html","UTF-8");
    }


}

To see the component in action please download source JustifyTextDemo

Enjoy

Thanks for reading.