How to get the exact text from "Edit Text" and install in text form in android

My problem is that I want to get the exact text from the edit text with the font that is installed in the text editor, as well as the text size, text color and text style, such as bold, italics and underline.

so far I have used Spannable, like this Spannable messageText; , and get the text from EditText, like this

  messageText = editText.getText(); 

and set to textview

  textView.setText(messageText); 

But in this case, it returns only a simple string, not 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" /> 

Help me thanks

+8
android android-edittext textview
source share
2 answers

If you set the background color of the edit text, like this

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

Then

Do this to get the background color.

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

And then set this color to textView.

 textView.setBackgroundColor(color); 
+4
source share

Hi, I have a sample project for you. I think you are expecting an answer.

This is 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> 

Operation code:

  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()); } }); 

I think this is what you expect.

+1
source share

All Articles