0

I’m trying to show a custom SnackBar inside of a CoordinatorLayout.. but the text inside is truncated and I’m not able to figure the reason for that.

enter image description here

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/layout_snackbar"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<string name="no_internet_snackbar">El dispositivo no cuenta con internet.\nFavor de intentar nuevamente.</string>



Snackbar snackbar;
    snackbar = Snackbar.make(parent, getAlertText(), Snackbar.LENGTH_SHORT);
    View snackBarView = snackbar.getView();
    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)snackbar.getView();
    //layout.setPadding(0, 0, 0, 0);
    /*CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) snackBarView.getLayoutParams();
    params.gravity = Gravity.TOP;
    snackBarView.setLayoutParams(params);*/
    snackBarView.setBackgroundColor(getAlertBackgroundColor());
    TextView textView = snackBarView.findViewById(android.support.design.R.id.snackbar_text);;
    textView.setTextColor(Color.WHITE);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setMaxLines(5);  // show multiple line
    textView.setTextSize(13);
    textView.setGravity(Gravity.CENTER);
    textView.setTop(90);
   /*textView.setMinLines(2);
    textView.setTextSize(12);

    textView.setSingleLine(false);
    textView.setLines(2);*/
    textView.setBackgroundColor(Color.BLACK);
    //textView.setWidth(parent.getWidth());
    //textView.setHeight(parent.getHeight());
    snackbar.show();

As you can see, I tried so many ways but the result is the same. Thanks in advance.

lightless07
  • 401
  • 6
  • 17

1 Answers1

0

Try to add the line of code

<integer name="design_snackbar_text_max_lines">3</integer>

in res/value/string

Lucas
  • 458
  • 4
  • 6