Android 如何使文本视图中的部分文本加粗?

Android 如何使文本视图中的部分文本加粗?,android,textview,Android,Textview,我有这个文本视图: ((TextView)findViewById(R.id.carmodel)).setText("CarModel: " + getCarModel+""); ((TextView)findViewById(R.id.bikemodel)).setText("BikeModel: " + getBikeModel+""); 有没有一种方法可以将CarModel:和BikeModel:加粗 这是XML文件: <TextView android:id="@+id/

我有这个文本视图:

((TextView)findViewById(R.id.carmodel)).setText("CarModel: " + getCarModel+"");
((TextView)findViewById(R.id.bikemodel)).setText("BikeModel: " + getBikeModel+"");
有没有一种方法可以将CarModel:和BikeModel:加粗

这是XML文件:

<TextView
    android:id="@+id/carmodel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:textSize="17sp"
    android:textStyle="italic"
    android:layout_marginLeft="10dp"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
    android:id="@+id/bikemodel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:textSize="17sp"
    android:textStyle="italic"
    android:layout_marginLeft="10dp"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall" />


因此
getCarModel
getBikeModel
将是斜体,
CarModel
BikeModel:
粗体。

有很多方法可以实现您想要的

1) 您可以在文本视图中插入HTML,如“Tanis”所述

并根据需要使用ID“carmodelBold”设置文本视图的样式


3) 您可以创建一个表

第二种方法可能对我有帮助,但如何将它们放在一行上?因为如果我为粗体文本创建一个文本视图,为数据创建另一个文本视图,它们位于不同的行上?我相信您使用的是垂直方向的LinerLayout。你需要使用水平方向的线性布局。以防万一……你也可以嵌套布局。因此,如果您无法更改当前布局,请在其中创建一个具有所需方向的新布局,我使用LinearLayout,如果我将其更改为
水平
所有内容都将隐藏。。有没有关于如何使用嵌套布局的示例?请检查这些链接:这是否回答了您的问题?
((TextView)findViewById(R.id.carmodel)).setText(Html.fromHtml("<h2>CarModel: </h2>") + getCarModel+"");
((TextView)findViewById(R.id.carmodelBold)).setText("CarModel: ");    
((TextView)findViewById(R.id.carmodel)).setText(getCarModel);