如何从编辑文本中获取确切的文本并在android中设置为文本视图

Nav*_*mar 8 android textview android-edittext

我的问题是我希望从编辑文本中获取精确文本,其中包含在编辑文本中设置的字体以及文本大小,文本颜色和文本样式,如粗体,斜体和下划线.

到目前为止,我使用了像这样的Spannable Spannable messageText;并从EditText中获取这样的文本

 messageText = editText.getText();
Run Code Online (Sandbox Code Playgroud)

并设置为textview

 textView.setText(messageText);
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,它只返回简单的字符串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" />
Run Code Online (Sandbox Code Playgroud)

帮帮我,谢谢

Nar*_*Pal 4

如果您像这样设置编辑文本的背景颜色

 editText.setBackgroundDrawable(new PaintDrawable(Color.YELLOW));
Run Code Online (Sandbox Code Playgroud)

然后,

执行此操作以获得背景颜色。

PaintDrawable drawable = (PaintDrawable) editText.getBackground();
int color = drawable.getPaint().getColor();
Run Code Online (Sandbox Code Playgroud)

然后将此颜色设置到textView。

textView.setBackgroundColor(color); 
Run Code Online (Sandbox Code Playgroud)