Why does a Snackbar text disapear if the text is too long?
up vote
1
down vote
favorite
I have a requirement to add some user feedback using standard Snackbar in Android.
I have noticed that if my text is too long then the whole text string disappears. Rather than have an ellipses...
More specifically; on a Pixel 2 emulator the following string disappears:
"You're offline. Check your connection and try again." - This is gone
but if I remove the last character then it shows:
"You're offline. Check your connection and try again" - This shows
Even worse is that on a device with a smaller screen the length of the text that will show is reduced meaning on a Nexus 5 emulator for example:
"You're offline. Check your connection and try again" - This now doesn't show
but if I shorten it further:
"You're offline. Check your connection" - This shows
This feels like a bug to me.
I understand that Snackbar should be for very short text but none the less it shouldn't remove the text arbitrarily. It should at least show some text or an ellipses or go multi-line.
Has anyone else noticed this or can suggest if it's a bug or am I missing something?
Code example:
Snackbar.make(findViewById(R.id.placeSnackBar),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X", View.OnClickListener ).show()
I also tried:
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 for Coordinator layout which shows snackbar above floating footer layout:
<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>
How it looks with full string:
and if I shorten the string by 1 character:
android material-design material-ui snackbar
add a comment |
up vote
1
down vote
favorite
I have a requirement to add some user feedback using standard Snackbar in Android.
I have noticed that if my text is too long then the whole text string disappears. Rather than have an ellipses...
More specifically; on a Pixel 2 emulator the following string disappears:
"You're offline. Check your connection and try again." - This is gone
but if I remove the last character then it shows:
"You're offline. Check your connection and try again" - This shows
Even worse is that on a device with a smaller screen the length of the text that will show is reduced meaning on a Nexus 5 emulator for example:
"You're offline. Check your connection and try again" - This now doesn't show
but if I shorten it further:
"You're offline. Check your connection" - This shows
This feels like a bug to me.
I understand that Snackbar should be for very short text but none the less it shouldn't remove the text arbitrarily. It should at least show some text or an ellipses or go multi-line.
Has anyone else noticed this or can suggest if it's a bug or am I missing something?
Code example:
Snackbar.make(findViewById(R.id.placeSnackBar),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X", View.OnClickListener ).show()
I also tried:
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 for Coordinator layout which shows snackbar above floating footer layout:
<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>
How it looks with full string:
and if I shorten the string by 1 character:
android material-design material-ui snackbar
1
you should post your xml here. Maybe it's because of your xml viewplaceSnackBar
.
– Kingfisher Phuoc
Nov 12 at 17:14
As it works with 52 characters but not 51 on a pixel 2 emulator and even less on a smaller screen I don't think it is related but I can post it. Thanks
– Paul
Nov 12 at 23:11
@KingfisherPhuoc I shall eat my words you are on the money. It was the coordinator layout after all! Because I have a fixed height message bar container the bottom of the snack bar was being pushed down out of the visible area of the layout. I wish I could do an embarrassed emoji here :-) ... If you want me to mark your suggestion as correct answer then you can post it as an answer. Thanks for your suggestion.
– Paul
Nov 13 at 9:04
Cheers!! nvm, the cool thing is your issue was solved!
– Kingfisher Phuoc
Nov 13 at 9:37
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a requirement to add some user feedback using standard Snackbar in Android.
I have noticed that if my text is too long then the whole text string disappears. Rather than have an ellipses...
More specifically; on a Pixel 2 emulator the following string disappears:
"You're offline. Check your connection and try again." - This is gone
but if I remove the last character then it shows:
"You're offline. Check your connection and try again" - This shows
Even worse is that on a device with a smaller screen the length of the text that will show is reduced meaning on a Nexus 5 emulator for example:
"You're offline. Check your connection and try again" - This now doesn't show
but if I shorten it further:
"You're offline. Check your connection" - This shows
This feels like a bug to me.
I understand that Snackbar should be for very short text but none the less it shouldn't remove the text arbitrarily. It should at least show some text or an ellipses or go multi-line.
Has anyone else noticed this or can suggest if it's a bug or am I missing something?
Code example:
Snackbar.make(findViewById(R.id.placeSnackBar),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X", View.OnClickListener ).show()
I also tried:
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 for Coordinator layout which shows snackbar above floating footer layout:
<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>
How it looks with full string:
and if I shorten the string by 1 character:
android material-design material-ui snackbar
I have a requirement to add some user feedback using standard Snackbar in Android.
I have noticed that if my text is too long then the whole text string disappears. Rather than have an ellipses...
More specifically; on a Pixel 2 emulator the following string disappears:
"You're offline. Check your connection and try again." - This is gone
but if I remove the last character then it shows:
"You're offline. Check your connection and try again" - This shows
Even worse is that on a device with a smaller screen the length of the text that will show is reduced meaning on a Nexus 5 emulator for example:
"You're offline. Check your connection and try again" - This now doesn't show
but if I shorten it further:
"You're offline. Check your connection" - This shows
This feels like a bug to me.
I understand that Snackbar should be for very short text but none the less it shouldn't remove the text arbitrarily. It should at least show some text or an ellipses or go multi-line.
Has anyone else noticed this or can suggest if it's a bug or am I missing something?
Code example:
Snackbar.make(findViewById(R.id.placeSnackBar),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X", View.OnClickListener ).show()
I also tried:
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 for Coordinator layout which shows snackbar above floating footer layout:
<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>
How it looks with full string:
and if I shorten the string by 1 character:
android material-design material-ui snackbar
android material-design material-ui snackbar
edited Nov 12 at 23:17
asked Nov 9 at 18:44
Paul
667
667
1
you should post your xml here. Maybe it's because of your xml viewplaceSnackBar
.
– Kingfisher Phuoc
Nov 12 at 17:14
As it works with 52 characters but not 51 on a pixel 2 emulator and even less on a smaller screen I don't think it is related but I can post it. Thanks
– Paul
Nov 12 at 23:11
@KingfisherPhuoc I shall eat my words you are on the money. It was the coordinator layout after all! Because I have a fixed height message bar container the bottom of the snack bar was being pushed down out of the visible area of the layout. I wish I could do an embarrassed emoji here :-) ... If you want me to mark your suggestion as correct answer then you can post it as an answer. Thanks for your suggestion.
– Paul
Nov 13 at 9:04
Cheers!! nvm, the cool thing is your issue was solved!
– Kingfisher Phuoc
Nov 13 at 9:37
add a comment |
1
you should post your xml here. Maybe it's because of your xml viewplaceSnackBar
.
– Kingfisher Phuoc
Nov 12 at 17:14
As it works with 52 characters but not 51 on a pixel 2 emulator and even less on a smaller screen I don't think it is related but I can post it. Thanks
– Paul
Nov 12 at 23:11
@KingfisherPhuoc I shall eat my words you are on the money. It was the coordinator layout after all! Because I have a fixed height message bar container the bottom of the snack bar was being pushed down out of the visible area of the layout. I wish I could do an embarrassed emoji here :-) ... If you want me to mark your suggestion as correct answer then you can post it as an answer. Thanks for your suggestion.
– Paul
Nov 13 at 9:04
Cheers!! nvm, the cool thing is your issue was solved!
– Kingfisher Phuoc
Nov 13 at 9:37
1
1
you should post your xml here. Maybe it's because of your xml view
placeSnackBar
.– Kingfisher Phuoc
Nov 12 at 17:14
you should post your xml here. Maybe it's because of your xml view
placeSnackBar
.– Kingfisher Phuoc
Nov 12 at 17:14
As it works with 52 characters but not 51 on a pixel 2 emulator and even less on a smaller screen I don't think it is related but I can post it. Thanks
– Paul
Nov 12 at 23:11
As it works with 52 characters but not 51 on a pixel 2 emulator and even less on a smaller screen I don't think it is related but I can post it. Thanks
– Paul
Nov 12 at 23:11
@KingfisherPhuoc I shall eat my words you are on the money. It was the coordinator layout after all! Because I have a fixed height message bar container the bottom of the snack bar was being pushed down out of the visible area of the layout. I wish I could do an embarrassed emoji here :-) ... If you want me to mark your suggestion as correct answer then you can post it as an answer. Thanks for your suggestion.
– Paul
Nov 13 at 9:04
@KingfisherPhuoc I shall eat my words you are on the money. It was the coordinator layout after all! Because I have a fixed height message bar container the bottom of the snack bar was being pushed down out of the visible area of the layout. I wish I could do an embarrassed emoji here :-) ... If you want me to mark your suggestion as correct answer then you can post it as an answer. Thanks for your suggestion.
– Paul
Nov 13 at 9:04
Cheers!! nvm, the cool thing is your issue was solved!
– Kingfisher Phuoc
Nov 13 at 9:37
Cheers!! nvm, the cool thing is your issue was solved!
– Kingfisher Phuoc
Nov 13 at 9:37
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Set your snackbar lines to 2 by accessing its TextView
:
val message = "You're offline. Check your connection and try again.";
val sb = Snackbar.make(
findViewById(R.id.newLinearLayout),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X")
val view = sb.view
val textView = view.findViewById<View>(android.support.design.R.id.snackbar_text) as TextView
textView.maxLines = 2
sb.show()
I tried this and also singleLine = false and no joy :-(
– Paul
Nov 12 at 16:58
@Paul you must be doing something wrong because it works as expected. But check this: even if you see no text does it look to you that its height is long enough to hold 2 lines?
– forpas
Nov 12 at 17:07
@Paul I updated with the Kotlin code
– forpas
Nov 12 at 18:35
I have tried that exact code and same issue. I even pasted your code directly just in case and still get the exact same result. Thanks, Paul.
– Paul
Nov 12 at 23:08
thanks for your suggestions I found the issue you it was related to my coordinator layout see answer in question comments above with KingfisherPhuoc. Paul.
– Paul
Nov 13 at 9:06
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Set your snackbar lines to 2 by accessing its TextView
:
val message = "You're offline. Check your connection and try again.";
val sb = Snackbar.make(
findViewById(R.id.newLinearLayout),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X")
val view = sb.view
val textView = view.findViewById<View>(android.support.design.R.id.snackbar_text) as TextView
textView.maxLines = 2
sb.show()
I tried this and also singleLine = false and no joy :-(
– Paul
Nov 12 at 16:58
@Paul you must be doing something wrong because it works as expected. But check this: even if you see no text does it look to you that its height is long enough to hold 2 lines?
– forpas
Nov 12 at 17:07
@Paul I updated with the Kotlin code
– forpas
Nov 12 at 18:35
I have tried that exact code and same issue. I even pasted your code directly just in case and still get the exact same result. Thanks, Paul.
– Paul
Nov 12 at 23:08
thanks for your suggestions I found the issue you it was related to my coordinator layout see answer in question comments above with KingfisherPhuoc. Paul.
– Paul
Nov 13 at 9:06
add a comment |
up vote
0
down vote
Set your snackbar lines to 2 by accessing its TextView
:
val message = "You're offline. Check your connection and try again.";
val sb = Snackbar.make(
findViewById(R.id.newLinearLayout),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X")
val view = sb.view
val textView = view.findViewById<View>(android.support.design.R.id.snackbar_text) as TextView
textView.maxLines = 2
sb.show()
I tried this and also singleLine = false and no joy :-(
– Paul
Nov 12 at 16:58
@Paul you must be doing something wrong because it works as expected. But check this: even if you see no text does it look to you that its height is long enough to hold 2 lines?
– forpas
Nov 12 at 17:07
@Paul I updated with the Kotlin code
– forpas
Nov 12 at 18:35
I have tried that exact code and same issue. I even pasted your code directly just in case and still get the exact same result. Thanks, Paul.
– Paul
Nov 12 at 23:08
thanks for your suggestions I found the issue you it was related to my coordinator layout see answer in question comments above with KingfisherPhuoc. Paul.
– Paul
Nov 13 at 9:06
add a comment |
up vote
0
down vote
up vote
0
down vote
Set your snackbar lines to 2 by accessing its TextView
:
val message = "You're offline. Check your connection and try again.";
val sb = Snackbar.make(
findViewById(R.id.newLinearLayout),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X")
val view = sb.view
val textView = view.findViewById<View>(android.support.design.R.id.snackbar_text) as TextView
textView.maxLines = 2
sb.show()
Set your snackbar lines to 2 by accessing its TextView
:
val message = "You're offline. Check your connection and try again.";
val sb = Snackbar.make(
findViewById(R.id.newLinearLayout),
"You're offline. Check your connection and try again.",
Snackbar.LENGTH_INDEFINITE)
.setAction("X")
val view = sb.view
val textView = view.findViewById<View>(android.support.design.R.id.snackbar_text) as TextView
textView.maxLines = 2
sb.show()
edited Nov 12 at 18:34
answered Nov 9 at 18:53
forpas
3,3071214
3,3071214
I tried this and also singleLine = false and no joy :-(
– Paul
Nov 12 at 16:58
@Paul you must be doing something wrong because it works as expected. But check this: even if you see no text does it look to you that its height is long enough to hold 2 lines?
– forpas
Nov 12 at 17:07
@Paul I updated with the Kotlin code
– forpas
Nov 12 at 18:35
I have tried that exact code and same issue. I even pasted your code directly just in case and still get the exact same result. Thanks, Paul.
– Paul
Nov 12 at 23:08
thanks for your suggestions I found the issue you it was related to my coordinator layout see answer in question comments above with KingfisherPhuoc. Paul.
– Paul
Nov 13 at 9:06
add a comment |
I tried this and also singleLine = false and no joy :-(
– Paul
Nov 12 at 16:58
@Paul you must be doing something wrong because it works as expected. But check this: even if you see no text does it look to you that its height is long enough to hold 2 lines?
– forpas
Nov 12 at 17:07
@Paul I updated with the Kotlin code
– forpas
Nov 12 at 18:35
I have tried that exact code and same issue. I even pasted your code directly just in case and still get the exact same result. Thanks, Paul.
– Paul
Nov 12 at 23:08
thanks for your suggestions I found the issue you it was related to my coordinator layout see answer in question comments above with KingfisherPhuoc. Paul.
– Paul
Nov 13 at 9:06
I tried this and also singleLine = false and no joy :-(
– Paul
Nov 12 at 16:58
I tried this and also singleLine = false and no joy :-(
– Paul
Nov 12 at 16:58
@Paul you must be doing something wrong because it works as expected. But check this: even if you see no text does it look to you that its height is long enough to hold 2 lines?
– forpas
Nov 12 at 17:07
@Paul you must be doing something wrong because it works as expected. But check this: even if you see no text does it look to you that its height is long enough to hold 2 lines?
– forpas
Nov 12 at 17:07
@Paul I updated with the Kotlin code
– forpas
Nov 12 at 18:35
@Paul I updated with the Kotlin code
– forpas
Nov 12 at 18:35
I have tried that exact code and same issue. I even pasted your code directly just in case and still get the exact same result. Thanks, Paul.
– Paul
Nov 12 at 23:08
I have tried that exact code and same issue. I even pasted your code directly just in case and still get the exact same result. Thanks, Paul.
– Paul
Nov 12 at 23:08
thanks for your suggestions I found the issue you it was related to my coordinator layout see answer in question comments above with KingfisherPhuoc. Paul.
– Paul
Nov 13 at 9:06
thanks for your suggestions I found the issue you it was related to my coordinator layout see answer in question comments above with KingfisherPhuoc. Paul.
– Paul
Nov 13 at 9:06
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231647%2fwhy-does-a-snackbar-text-disapear-if-the-text-is-too-long%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
you should post your xml here. Maybe it's because of your xml view
placeSnackBar
.– Kingfisher Phuoc
Nov 12 at 17:14
As it works with 52 characters but not 51 on a pixel 2 emulator and even less on a smaller screen I don't think it is related but I can post it. Thanks
– Paul
Nov 12 at 23:11
@KingfisherPhuoc I shall eat my words you are on the money. It was the coordinator layout after all! Because I have a fixed height message bar container the bottom of the snack bar was being pushed down out of the visible area of the layout. I wish I could do an embarrassed emoji here :-) ... If you want me to mark your suggestion as correct answer then you can post it as an answer. Thanks for your suggestion.
– Paul
Nov 13 at 9:04
Cheers!! nvm, the cool thing is your issue was solved!
– Kingfisher Phuoc
Nov 13 at 9:37