我的问题是我希望从编辑文本中获取精确文本,其中包含在编辑文本中设置的字体以及文本大小,文本颜色和文本样式,如粗体,斜体和下划线 .
直到现在我使用像这样的 Spannable messageText;
的Spannable并从这里获取EditText的文本
messageText = editText.getText();
并设置为textview
textView.setText(messageText);
但在这种情况下,它只返回简单的字符串而不是 color,font,size and style
.
EditText
<EditText
android:id="@+id/message"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:inputType="textMultiLine"
android:singleLine="false"
android:tag="no"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="normal"
android:typeface="normal" />
TextView
<TextView
android:id="@+id/preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="normal"
android:typeface="normal" />
帮帮我,谢谢
2 回答
如果您正在设置编辑文本的背景颜色,请执行此操作
然后,
Do this to get the background color.
And then set this color to the textView.
嗨,我已经为你运行了示例项目..我想你期待这个答案..
这是xml:
活动代码:
我想这就是你所期待的 .