2012-12-28 21 views
8

में टेक्स्ट व्यू में कैसे सेट करें मेरी समस्या यह है कि मैं पाठ संपादित करने के साथ-साथ पाठ आकार, टेक्स्ट रंग और टेक्स्ट शैली में सेट किए गए फ़ॉन्ट के साथ टेक्स्ट संपादित करने से सटीक टेक्स्ट प्राप्त करना चाहता हूं। बोल्ड, इटैलिक और अंडरलाइन की तरह।संपादन टेक्स्ट से सटीक टेक्स्ट कैसे प्राप्त करें और एंड्रॉइड

अब तक मैं इस Spannable messageText; तरह Spannable का इस्तेमाल किया और इस

messageText = editText.getText(); 

तरह EditText से पाठ हो और 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 फ़ाइल में टेक्स्टव्यू के लिए विशेषता आपके संपादन टेक्स्ट में समान रूप से सेट की गई है .. – Subburaj

+0

संपादन टेक्स्ट के लिए प्रोग्रामेटिक रूप से रंग, फ़ॉन्ट, आकार और शैली बनाएं, और जब संपादन टेक्स्ट से डेटा लाने से टेक्स्ट व्यू में सभी बनाए गए विशेषताओं को सेट किया जाए जहां आप संपादन की स्ट्रिंग को पार कर रहे हैं टेक्स्ट –

+0

@ शुब्बराज नहीं, यह टेक्स्टव्यू –

उत्तर

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

पर कोशिश कर रहा हूं, मैंने अपनी समस्या हल की है, बस संपादन से रंग, आकार और फ़ॉन्ट प्राप्त करें टेक्स्ट और टेक्स्टव्यू में सेट करें। धन्यवाद और खुश कोडिंग –

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

      } 
     }); 

मुझे लगता है कि यह वही है जो आप उम्मीद कर रहे हैं।

संबंधित मुद्दे