gpt4 book ai didi

android - 如何从编辑文本中获取准确的文本并在android中设置为 TextView

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:54:59 24 4
gpt4 key购买 nike

我的问题是,我想从编辑文本中获取准确的文本,其字体在编辑文本中设置,以及文本大小、文本颜色和文本样式,如粗体、斜体和下划线。

直到现在我像这样使用 Spannable Spannable messageText; 并像这样从 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" />

帮帮我,谢谢

最佳答案

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

 editText.setBackgroundDrawable(new PaintDrawable(Color.YELLOW));

然后,

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

PaintDrawable drawable = (PaintDrawable) editText.getBackground();
int color = drawable.getPaint().getColor();

然后将这个颜色设置到textView。

textView.setBackgroundColor(color); 

关于android - 如何从编辑文本中获取准确的文本并在android中设置为 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14065210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com