【发布时间】:2012-12-13 11:09:39
【问题描述】:
我的问题是,我想从编辑文本中获取准确的文本,其字体在编辑文本中设置,以及文本大小、文本颜色和文本样式,如粗体、斜体和下划线。
直到现在我像这样使用 Spannable Spannable messageText; 并像这样从 EditText 获取文本
messageText = editText.getText();
并设置到文本视图中
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" />
帮帮我,谢谢
【问题讨论】:
-
在 xml 文件中将 textview 的属性设置为与您的编辑文本中相同..
-
以编程方式为editText创建颜色、字体、大小和样式,并在从editText获取数据时将所有创建的属性设置为传递editText字符串的textView
-
@Subburaj 不,它没有改变 textview 的所有属性
-
你能发布你的xml有这个Edittext和textview吗??
-
@nick 我已经以编程方式为 editText 设置了颜色、字体、大小和样式。但我不知道如何为文本视图设置所有这些值
标签: android textview android-edittext