3

I have something like "There are 200€" but I want to style the value (ex. textColor Red)

Is there any way of having two textViews to seem like an entire one?

A textView inside a textView or a textViewContainer or something.

I can achieve it on the run like this answer: Change text color of one word in a TextView

But I want to do from the layout file. Any chance?

Thanks

EDIT

<TextView
    android:id="@+id/lastIncome"
    android:text="Tu último ingreso fueron"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="@dimen/dash_font_size"/>
<TextView
    android:id="@+id/lastIncomeValue"
    android:text="200€"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="@dimen/dash_value_font_size"
    android:textColor="@color/greensea"
    android:layout_gravity="right"/>
Community
  • 1
  • 1
Jorge Chip
  • 81
  • 3
  • 9
  • Please post some code. For example, post how the text views are being created and laid out. – Sumner Evans Mar 29 '14 at 21:04
  • Just having two text views. Forget everything else. Just want the simple action of continue on the same line with a new textView with another style – Jorge Chip Mar 29 '14 at 21:18
  • Please post the code anyway. – Sumner Evans Mar 29 '14 at 21:20
  • If this is even a concern of yours anymore, you could check out this library: https://github.com/quiqueqs/BabushkaText Spannables are what I think you're looking for – TeePaps Dec 07 '14 at 16:56
  • Noone provide an answer, even I posted the code. It is not possible. Maybe you would prefer to change textSize for every screen size to place your textViews side by side. – Jorge Chip Apr 12 '14 at 16:39
  • @jorgechip Use linear layout with a horizontal orientation. This may help you – Shivam May 21 '19 at 14:09

2 Answers2

2

You can achieve this with a horizontal LinearLayout. The LinearLayout is the container for the two side by side TextViews. This layout can be placed in any other container (LinearLayout, RelativeLayout, etc.) in your XML.

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="There are " />
    <TextView
        android:id="@+id/amount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="200€"
        android:textColor="#ff0000"/>
</LinearLayout>
TeePaps
  • 471
  • 3
  • 17
  • What happens if "There are" is longer like "Your incomes are about" and it fills out all the screen width? The value will appear outside – Jorge Chip Mar 29 '14 at 21:29
  • In that case you can try `RelativeLayout` instead of Linear as a container and align `@+id/amount` text view to "follow" your other `TextView` – kiruwka Mar 29 '14 at 21:40
  • 2
    As I understand, textViews are like blocks. So if I define a RelativeLayout and then told inline `@+id/amount` to be below or at right of the first textView it will skip a lot of space as the form first textView is shaped is a rectangle no matters when the text finishs – Jorge Chip Mar 29 '14 at 21:44
1

You can use a easy approach to do this within one textview using SpanableString Builder Click here to get this approach