-1

I want the background color (blue) to be applied only where I have letters. Check the image below

Click here to see the example

Not aligned to the right example

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
chrisma
  • 1
  • 1

2 Answers2

1

Set layout width to wrap content

JakeB
  • 2,043
  • 3
  • 12
  • 19
  • ty! it solved the problem but then i have another problem which is that the text is alligned to the left. https://stackoverflow.com/questions/4768738/android-textview-remove-spacing-and-padding-on-top-and-bottom -> is says that i shall use match parent but that is the oppsosite of the suggested solution. what shall i do? – chrisma Oct 30 '20 at 15:14
  • set gravity Right on the linearLayout – JakeB Oct 30 '20 at 15:27
  • works a bit better but not exactly. my code looks like this: LinearLayout linearLayout = findViewById(R.id.ScrolledLinearLayout); linearLayout.setGravity(Gravity.RIGHT); TextView textView = new TextView(this); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); textView.setGravity(Gravity.RIGHT); textView.setBackgroundResource(R.color.blue); textView.setTextColor(ContextCompat.getColor(this, R.color.white)); check my 2nd picture above to see how it looks like – chrisma Oct 30 '20 at 17:20
  • LinearLayout needs to match parent – JakeB Oct 30 '20 at 19:01
0

set TextView width as wrap content, then color will be only in text area

Abu Saeed
  • 1,020
  • 8
  • 21