2012-12-28 19 views
8

我的问题文本的看法是这样我想从编辑的文字与字体,在编辑文本设置以及字体大小,字体颜色和文字样式确切文本如粗体,斜体和下划线。如何从编辑文本的确切文本,并设置成机器人

到现在我使用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" /> 

帮助我,谢谢

+1

在xml文件中,将textview的属性设置为与编辑文本中的相同。 – Subburaj

+0

为editText创建编程的颜色,字体,大小和样式,并且当从editText获取数据时将所有创建的属性设置为textView你在哪里传递EDITTEXT –

+0

@Subburaj的字符串中没有它是不会改变的TextView –

回答

4

如果要设置编辑文本的这样

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

然后背景颜色,

这样做是为了获得背景色。

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

,然后将该颜色TextView的。对于you..I

textView.setBackgroundColor(color); 
+0

是的,我想尼克 –

+1

我解决我的问题只是得到了编辑的颜色,大小和字体文本并设置到textview中。感谢和快乐编码 –

+0

很高兴帮助你交配 –

1

您好我已经跑示例项目想你期待这个答案..

这是XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <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="#1DA237" 
     android:textSize="15sp" 
     android:textStyle="italic" 
     android:typeface="normal" /> 


    <TextView 
      android:id="@+id/preview" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="subbu" 
      android:textColor="#1DA237" 
      android:textSize="15sp" 
      android:textStyle="italic" 
      android:typeface="normal" 
      android:paddingBottom="50dp" 
      android:layout_below="@+id/message"/> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 

     android:layout_marginRight="29dp" 
     android:layout_marginTop="93dp" 
     android:text="Button" 
     android:layout_below="@+id/preview"/> 

</RelativeLayout> 

活动代码:

final EditText text=(EditText)findViewById(R.id.message); 

     Button b=(Button)findViewById(R.id.button1); 
     final TextView t=(TextView)findViewById(R.id.preview); 

     b.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       t.setText(text.getText().toString()); 

      } 
     }); 

我觉得这是你期待什么。

相关问题