is there any way to make a SnackBar wrapping its text content?
You can look up my problem below:
As you can see the text ends at "contact us at...." and it should display the entire message.
Thank you!
I believe that snackbar by default limits you to only 2 lines.
One thing that you could try is setting the textview inside snackbar to be multiline. Like so:
View snackbarView = snackbar.getView();
TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
textView.setMaxLines(5); //set the max lines for textview to show multiple lines
Let me know if that works or not
Related
The text view tv_title is always displayed above the activity even though when I've set bottom margin 0dp.
Here is the screenshot:
Also when bottom margin is 10 dp, the text view goes further up:
I hope I understood the problem, since the question isn't clear (I don't understand what's the outcome you want) and you didn't add your whole xml code.
tv_title and tv_desc have 120dp space between them because tv_desc has marginTop 120dp. When you add marginBottom = 10dp to tv_title, the space equals to 130dp.
In RelativeLayout, if you want to display tv_title beneath tv_desc, add layout_below field to tv_title.
And it would be better for you to see some RelativeLayout examples.
May be you are using noactionbar theme so it does't appear . but if you want using without actionbar than just use :
android:layout_marginTop="?attr/actionBarSize"
this may help.
or Use :
remove android:layout_above="#+id/tv_desc" from tv_title textview. and add android:layout_below="#+id/tv_title" in tv_desc textview will help you.
I have colored my snackbar. But this snackbar shows a small white stripe at the bottom and anotherone at the top.
You can see it inside the two red frames (which are not part of my app - just shown here for demonstration). The darker I choose the background, the better you can see these stripes.
The stripes are coming from the MainActivity Background. When I change this background color, the color of these stripes are also changing there color.
I played around with some padding on the two text fields, but didn't find a solution to loose these stripes.
How can I get rid of this white stripe?
View contextView = findViewById(android.R.id.content);
Snackbar snackbar = Snackbar
.make(contextView, "HELLO", Snackbar.LENGTH_SHORT)
.setDuration(3500)
.setActionTextColor(getResources().getColor(R.color.korall));
// Change the Snackbar default text color
View snackbarView = snackbar.getView();
TextView tv = (TextView) snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
tv.setTextColor(getResources().getColor(R.color.nightPrimaryLight));
tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
tv.setPadding(24,52,0,52);
TextView tva = snackbarView.findViewById(com.google.android.material.R.id.snackbar_action);
tva.setTextColor(getResources().getColor(R.color.korall));
tva.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
tva.setPadding(0,34,24,24);
tva.setBackgroundColor(getResources().getColor(R.color.grey));
tv.setBackgroundColor(getResources().getColor(R.color.grey));
snackbar.show();;
How can I prevent a TextView, or any visual object, from wrapping to the screen and instead have them cropped programmatically?
I have a table view which is loaded with TextViews as cells. I need to crop the text inside the textview instead of wrapping.
Is there some code to do this? or is there any workaround?
For example, I have like this:
But what I want is:
I found my own way to fix this. I set the textView.SetMaxLines to 1 and it solved the problem for me.
You can use setSingleLine method:
TextView textView = (TextView) findViewById(...);
textView.setSingleLine(true);
and setEllipsize to remove ellipsize:
textView.setEllipsize(null);
I built a linear layout inside of a dialog , the problem here that i want to change the TextView of this layout but i don't know how ! ,, any help ?
The same way you would do it with a normal view.
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText("Hello");
I am adding Linearlayout dynamically and adding 3 TextView getting the content from webservices for text view if the content of 3 text size is larger it will display in the end of next line .i want display in start line how can i do?
Thanks
TextView header_text;
header_text = (TextView) findViewById(R.id.header_text1);
header_text.setSingleLine();
try to use android:gravity="left" or alignParent="left"
To align your Text inside a specific TextView:
Textview t = (Textview) findViewbyid(R.id.yourView); //refernce to your View
t.setGravity(Gravity.RIGHT); //or any align you want
t.setText("String text or long string");