I am tyring to display a TextView that contains two sentences and I want them to be one after the other like this:
AAAAAA: BBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBB
where A... is the first word\part of sentence and B... is a second sentence.
the size of A... & B... isn't constant.
tried doing this:
<RelativeLayout
style="@style/f13"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/first_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAAA: " />
<TextView
style="@style/f15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
android:layout_toRightOf="@id/first_text" />
</RelativeLayout>
but i got:
AAAAAA: BBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBB
and i want the second (B...) sentence to continue below the first sentence (A...) i should add that sentence A... & B... have different styles.
the style for A:
<style
name="f13">
<item name="android:typeface">sans</item>
<item name="android:textSize">15dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/grey_dark_emperor</item>
</style>
the style for B:
<style
name="f15">
<item name="android:typeface">sans</item>
<item name="android:textSize">17dp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">@color/grey_dark_emperor</item>
</style>
any thoughts ?
There are many ways to make multiple styles inside android TextView and in this example I have made multiple style with three different ways using HTML tags and Html. fromHtml().
Text styling is one of the important aspects when it comes to enhancing the UI of an Android application. In Android, we can change the size, color, weight, style, etc of a text and make the text more attractive and appealing.
You can try to use the SpannableStringBuilder as follows:
String firstString = "AAAAAA: ";
String secondString = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(firstString + secondString);
stringBuilder.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, firstString.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
stringBuilder.setSpan(new ForegroundColorSpan(Color.rgb(255, 0, 0)), firstString.length() + 1,
firstString.length() + secondString.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(stringBuilder);
This will make the first sentence to be bold, and the second one coloured in red.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With