简体   繁体   中英

Android - Snackbar with multiline text

I have SnackBar with text but i need more than one line.

this is my code:

import android.support.design.widget.Snackbar;

final String snack = "LINE1\nLINE2\nLINE3";
Snackbar.make(view, snack, Snackbar.LENGTH_LONG).show();

there is a way to do it with SnackBar?

try this you have to use maxLines attribute of Snackbars Textview

Snackbar snackbar =  Snackbar.make(view, "LINE1\nLINE2\nLINE3",Snackbar.LENGTH_LONG).setDuration(Snackbar.LENGTH_LONG);
View snackbarView = snackbar.getView();
TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
textView.setMaxLines(5);
snackbar.show();

you may try this

View mySnackbarView= snackbar.getView();
TextView tv= (TextView) mySnackbarView.findViewById(android.support.design.R.id.snackbarText);
tv.setMaxLines(2); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM