1

I have a Textview which I have given a custom font. How best can I apply justification to the the same Textview.

This is how I applied the custom font

<extension.ezyagric.com.android.Widgets.FiraTextView
            android:id="@+id/body"
            android:paddingTop="5dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="fill_vertical"
            android:layout_below="@+id/thumbnail"
            android:textColor="@color/black"
            android:textSize="15sp" />

And this is the library I had tried to use to justify the Textview but i failed to achieve what I wanted

<me.biubiubiu.justifytext.library.JustifyTextView
            android:id="@+id/body"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingEnd="10dp"
            android:paddingRight="10dp"
            android:paddingLeft="10dp"
            android:fontFamily="@assets/Roboto-Bold"
            android:layout_below="@+id/thumbnail"
            android:textColor="@color/black"
            android:textSize="15sp" />

And indeed the library can justify the Textview. But how can I achieve both applying the custom fonts and the justify the Textview. Any help is highly welcome. Thanks in advance

Raphael
  • 291
  • 1
  • 3
  • 16

1 Answers1

1

I finally got a workaround. I applied the justication on the xml and set the custom font from the activity and in particular the adapter. The xml

<me.biubiubiu.justifytext.library.JustifyTextView
            android:paddingTop="2dp"
            android:textColor="@color/black"
            android:id="@+id/control"
            android:layout_gravity="fill"
            android:layout_below="@+id/cntrl_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="15sp" />

The dapter

public class DiagAdapter extends RecyclerView.Adapter<DiagAdapter.ViewHolder> {
private Context mContext;
ArrayList<JsonObject> diagItem = new ArrayList<>();
public Typeface tf;

This is the context

public DiagAdapter(Context context, ArrayList<JsonObject> diagItem) {
    this.diagItem = diagItem;
    this.mContext = context;
    this.tf = Typeface.createFromAsset(context.getAssets(), "FiraSans-Light.ttf");
}

And this is how I applied it

   viewHolder.cause.setText(sl.has("cause")?sl.get("cause").getAsString():"");
        viewHolder.cause.setTypeface(tf);
Raphael
  • 291
  • 1
  • 3
  • 16