Android多行小吃店 [英] Android Multiline Snackbar

查看:97
本文介绍了Android多行小吃店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试利用Android设计支持库中的新Snackbar来显示多行小吃栏,如

I'm trying to leverage new Snackbar from Android Design Support Library to display multiline snackbar, as shown in http://www.google.com/design/spec/components/snackbars-toasts.html#snackbars-toasts-specs:

import android.support.design.widget.Snackbar;

final String snack = "First line\nSecond line\nThird line";
Snackbar.make(mView, snack, Snackbar.LENGTH_LONG).show();

它在我的Nexus 7上仅显示First line....如何使其显示所有行?

It displays only First line... on my Nexus 7. How to make it display all lines?

PS:我尝试了Toast,它显示了所有行.

PS: I tried Toast and it displayed all lines.

推荐答案

只需设置Snackbars Textview的maxLines属性

Just set the maxLines attribute of Snackbars Textview

View snackbarView = snackbar.getView();
TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
textView.setMaxLines(5);  // show multiple line

如果您使用的是最新的"com.google.android.material:material:1.0.0"依赖项,则将使用以下内容:com.google.android.material.R.id.snackbar_text来访问Snackbar的TextView.

您甚至可以使用R.id.snackbar_text.这对我有用.

If you're using the more recent "com.google.android.material:material:1.0.0"dependency, then you will use this: com.google.android.material.R.id.snackbar_text to access the Snackbar's TextView.

You can use even R.id.snackbar_text as well. it's work for me.

这篇关于Android多行小吃店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆