KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I can use Spannable in TextViews to create spans with different looks, underlines, strikethroughs and such. How can I do the same to alter line wrapping behavior? In particular, I don't want an email address to wrap in the middle, I want it to act like one word. I tried WrapTogetherSpan , but I couldn't get it to work. It looks like it is only used by DynamicLayout, and I could not force the TextView to use DynamicLayout. <TextView android:id="@+id/merchant_email_field" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="@dimen/account_setting_email" android:gravity="center" android:bufferType="spannable" android:maxLines="2" android:ellipsize="end" /> How I'm setting the spannable: WrapTogetherSpan TOGETHER_SPAN = new WrapTogetherSpan() {}; String collectedString = getString(R.string.email_sentence, userEmail); int emailOffset = collectedString.indexOf(userEmail); Spannable emailSpannable = Spannable.Factory.getInstance() .newSpannable(collectedString); emailSpannable.setSpan(TOGETHER_SPAN, emailOffset, emailOffset + userEmail.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); textView.setText(emailSpannable)
Tags (comma-separated)
Save Edits
Cancel