【发布时间】:2019-04-13 08:56:48
【问题描述】:
我需要使用 Android 中的标准 Snackbar 添加一些用户反馈。
我注意到如果我的文本太长,那么整个文本字符串就会消失。而不是有一个省略号...
更具体地说;在 Pixel 2 模拟器上,以下字符串会消失:
“您处于离线状态。请检查您的连接,然后重试。” - 没了
但如果我删除最后一个字符,则会显示:
“您处于离线状态。请检查您的连接并重试” - 这表明
更糟糕的是,在屏幕较小的设备上,将显示的文本长度在 Nexus 5 模拟器上的含义会减少:
“您处于离线状态。请检查您的连接并重试” - 现在不显示
但如果我进一步缩短它:
“您处于离线状态。请检查您的连接” - 这表明
这对我来说就像一个错误。
我知道 Snackbar 应该是非常短的文本,但它不应该任意删除文本。它至少应该显示一些文本或省略号或多行。
有没有其他人注意到这一点,或者可以建议这是一个错误还是我遗漏了什么?
代码示例:
Snackbar.make(findViewById(R.id.placeSnackBar),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X", View.OnClickListener { }).show()
我也试过了:
val sb = Snackbar.make(this, message, Snackbar.LENGTH_INDEFINITE)
.setActionTextColor(Color.parseColor("#666666"))
.setAction("X", View.OnClickListener { })
sb.view.setBackgroundColor(Color.WHITE)
sb.view.findViewById<TextView>(android.support.design.R.id.snackbar_text)
//.setTextColor(Color.parseColor("#F44336"))
.setTextColor(Color.parseColor("#000000"))
sb.view.findViewById<TextView>(android.support.design.R.id.snackbar_text)
.singleLine = false
sb.view.findViewById<TextView>(android.support.design.R.id.snackbar_text)
.maxLines = 2
sb.show()
用于在浮动页脚布局上方显示小吃栏的协调器布局的 XML:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/message_bar_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_above="@+id/llFooter" />
<LinearLayout
android:id="@+id/llFooter"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="@drawable/footer_background"
android:orientation="horizontal"
android:paddingStart="20dp"
android:paddingEnd="20dp">
<TextView
android:id="@+id/login_forgot_password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
...
/>
<Button
android:id="@+id/btn_login"
android:layout_width="0dp"
android:layout_height="wrap_content"
...
/>
</LinearLayout>
</RelativeLayout>
完整字符串的样子:
如果我将字符串缩短 1 个字符:
【问题讨论】:
-
您应该在此处发布您的 xml。也许是因为你的 xml 视图
placeSnackBar. -
因为它适用于 52 个字符,但在像素 2 模拟器上不能使用 51 个字符,在较小的屏幕上甚至更少,我认为它不相关,但我可以发布它。谢谢
-
@KingfisherPhuoc 我会吃我的话,你有钱了。毕竟是协调器布局!因为我有一个固定高度的消息栏容器,所以小吃店的底部被推到了布局的可见区域之外。我希望我可以在这里做一个尴尬的表情符号:-) ...如果您希望我将您的建议标记为正确答案,那么您可以将其发布为答案。感谢您的建议。
-
干杯!! nvm,很酷的是你的问题已经解决了!
标签: android material-design material-ui snackbar