Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView inside a TextView

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"/>
like image 354
Jorge Chip Avatar asked Mar 16 '26 16:03

Jorge Chip


2 Answers

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>
like image 195
TeePaps Avatar answered Mar 18 '26 07:03

TeePaps


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

like image 32
Yatin Batra Avatar answered Mar 18 '26 08:03

Yatin Batra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!