Android的 - 两句话,两种风格,一是TextView的 [英] Android - two sentences, two styles, one TextView
问题描述
我tyring以显示包含两个句子一个TextView,我想他们是一个接一个像这样的:
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
其中,A ...是第一个字\句子和B的一部分......是第二句话。
where A... is the first word\part of sentence and B... is a second sentence.
A的大小...&放大器;乙...不是恒定的。
the size of A... & B... isn't constant.
试着这样做:
<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>
但我得到:
AAAAAA: BBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBB
和我想的第二个(B ...)的句子,继续下面的第一句话(A ...) 我要补充一点,判刑......&放大器;乙...有不同的风格。
and i want the second (B...) sentence to continue below the first sentence (A...) i should add that sentence A... & B... have different styles.
的风格答:
<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>
的风格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>
什么想法?
推荐答案
您可以尝试使用<一个href="http://developer.android.com/reference/android/text/SpannableStringBuilder.html">SpannableStringBuilder如下:
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.
这篇关于Android的 - 两句话,两种风格,一是TextView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!