是否可以为TextView中的不同文本设置多个样式?
例如,我将文本设置如下:
tv.setText(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3);
Run Code Online (Sandbox Code Playgroud)
是否可以为每个文本元素设置不同的样式?例如,line1粗体,word1斜体等.
开发人员指南的常见任务和Android中的操作方法包括选择,突出显示或设置部分文本样式:
Run Code Online (Sandbox Code Playgroud)// Get our EditText object. EditText vw = (EditText)findViewById(R.id.text); // Set the EditText's text. vw.setText("Italic, highlighted, bold."); // If this were just a TextView, we could do: // vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE); // to force it to use Spannable storage so styles can be attached. // Or we could specify that in the XML. // …
一个ListView在我的应用程序有很多字符串元素,如name,experience,date of joining,等我只是想name大胆.所有字符串元素都在一个单独的元素中TextView.
我的XML:
<ImageView
android:id="@+id/logo"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/logo"
android:padding="5dp"
android:textSize="12dp" >
</TextView>
Run Code Online (Sandbox Code Playgroud)
我的代码设置ListView项的TextView:
holder.text.setText(name + "\n" + expirience + " " + dateOfJoininf);
Run Code Online (Sandbox Code Playgroud)