Reputation: 2465
Is it possible to set alignment on a single line or some lines in multiline edittext android? If yes, then how, if no, then why not? I get this answer from another question posted under the similar topic
"You can't apply multiple alignments within the same editText control. You'd have to solve your problem with some kind of manual padding of the text content"
So how can manual padding be inserted for selected lines?
Upvotes: 2
Views: 610
Reputation: 531
you can use Alignment span to set alignment for a single line and multiple lines in multiline EditText provided you know the start and end index for the line. For example:
SpannableStringBuilder s = new SpannableStringBuilder("some text ");
AlignmentSpan span = new AlignmentSpan.Standard(Alignment.ALIGN_OPPOSITE);
s.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
t.setText(s);
You can apply alignment to multiple lines at once by covering multiple line between start and end index.
Upvotes: 2