是否可以为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. // …
I want a toast with multi-colors. Like this:

I looked at the different tutorials on changing the layout in the xml to create a custom Toast, but none of them explain adding different colors like this.
How can I do this?
================================
ANSWER
================================
Using all your help, I have designed a simple Method() to make color toasts easier to call.
res/layout/toast_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingBottom="6dp"
android:paddingTop="6dp"
android:background="#DAAA"
>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout> …Run Code Online (Sandbox Code Playgroud) 我使用Android Studio.我想在下面的照片中写出彩色文字EditText.我研究过,但我什么都没发现.谁能帮我?
样本输出如下.
这是我的代码.anaM_LV_BG_text是列表视图name_title,内容是edittextrenk_koduları_string_text是一个包含html颜色的数组
private void registerClickCallBack_text(){anaM_LV_BG_renk_text.setOnItemClickListener(new AdapterView.OnItemClickListener(){
private void registerClickCallBack_text() {
anaM_LV_BG_renk_text.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(DisplayNote.this, position + 1 + " . seçildi", Toast.LENGTH_SHORT).show();
name_title.setTextColor(Color.parseColor(renk_kodular?_string_text[position]));
content.setTextColor(Color.parseColor(renk_kodular?_string_text[position]));
SharedPreferences preferences_text = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor_text = preferences_text.edit();
String color_text= renk_kodular?_string_text[position];
editor_text.putString("MyColorText",color_text);
editor_text.commit();
}
});
}
Run Code Online (Sandbox Code Playgroud)