2011-12-29 20 views
14

मैं अपने एंड्रॉइड प्रोजेक्ट के लिए टेक्स्ट एरिया कैसे प्रदर्शित करूं? एक्सएमएल से, एकमात्र विकल्प टेक्स्टफिल्ड, बहु लाइन है। लेकिन संपादन योग्य है। मुझे टेक्स्टएरिया की आवश्यकता है जो केवल संदेश/टेक्स्ट प्रदर्शित करने के लिए उपयोगकर्ता द्वारा संपादन/इनपुट नहीं हो सकता है।एंड्रॉइड में टेक्स्टएरिया कैसे बनाएं

+0

आपको संपादन टेक्स्ट या टेक्स्ट व्यू जैसे शैली में कुछ चाहिए? – Robert

+0

इस उद्देश्य के लिए टेक्स्ट-व्यू का उपयोग करें यह आपके मामले के लिए सबसे उपयुक्त है। – Dharmendra

+0

टेक्स्टव्यू की समस्या मुझे लगता है कि यह दिखाता है कि यह मेरी पृष्ठभूमि का क्या है, जिसमें छवियों को पढ़ने में मुश्किल होती है –

उत्तर

7

इसका बहुत आसान, एक्सएमएल में इस कोड को लिखें:

<EditText 
    android:id="@+id/fname" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="First Name" 
/> 
6

उपयोग TextView एक ScrollView अंदर किसी भी संख्या लाइनों के साथ संदेशों को प्रदर्शित करने। उपयोगकर्ता इस दृश्य में टेक्स्ट को EditText में संपादित नहीं कर सकता है।

मुझे लगता है कि यह आपकी आवश्यकता के लिए अच्छा है। इसे एक बार कोशिश करें।

केवल यदि आप के रूप में नीचे उन्हें ठीक करना चाहते हैं आप XML फ़ाइल में डिफ़ॉल्ट रंग और पाठ का आकार बदल सकते हैं:

<TextView 
    android:id="@+id/tv" 
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
    android:textColor="#f00" 
    android:textSize="25px" 
    android:typeface="serif" 
    android:textStyle="italic"/> 

या आप जब भी आप नीचे के रूप में उपयोग करना चाहते हैं गतिशील रूप से परिवर्तित करना चाहते हैं:

TextView textarea = (TextView)findViewById(R.id.tv); // tv is id in XML file for TextView 
textarea.setTextSize(20); 
textarea.setTextColor(Color.rgb(0xff, 0, 0)); 
textarea.setTypeface(Typeface.SERIF, Typeface.ITALIC); 
+0

मुझे यह देखने की कोशिश करें कि यह कैसे –

+0

है हाँ यह मेरी आवश्यकता के लिए बहुत अच्छा है। अब मैं अपने फ़ॉन्ट/आकार/रंग कैसे बदलूं? डिफ़ॉल्ट पाठ ग्रे फीका-आईएसएच प्रतीत होता है, जो दृश्यता खराब है। –

+0

मुझे textarea.setTextSize (20) कहां रखना चाहिए; , ऐसा लगता है कि यह xml के लिए नहीं है। –

12

एक ScrollView

<ScrollView 
    android:id="@+id/ScrollView01" 
    android:layout_width="wrap_content" 
    android:layout_height="150dip"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

</ScrollView> 
+0

मैं इसमें बहु पंक्तिबद्ध विवरण कैसे डालूं? –

9

अंदर उपयोग TextView इसे आज़माएं:

<EditText 
     android:id="@+id/edit_text" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:inputType="text|textMultiLine" 
     android:gravity="top"/> 
+0

आम भाषा अंग्रेजी है। – Keelan

0

यह संक्षिप्त उत्तर किसी ऐसे व्यक्ति की मदद कर सकता है जो ऐसा करने की तलाश में है। अपने कोड

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:editable="false" 
    android:focusable="false" 
    android:singleLine="true" /> 
1

एक Android Mulitline EditText फील्ड को परिभाषित करने में इस सरल कोड जोड़ inputType = "textMultiline" के माध्यम से किया जाता है। दुर्भाग्यवश पाठ अजीब तरह से गठबंधन दिखता है। हल करने के लिए भी गुरुत्वाकर्षण = "बाएं | शीर्ष" विशेषता का उपयोग करें।

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:ems="10" 
    android:gravity="left|top" 
    android:inputType="textMultiLine" > 

    <requestFocus /> 

जांच इस vogella blog

0

और अगर आप रंग के साथ समस्या है, तो चिंता न। है सबसे अच्छा विकल्प यहाँ

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="text" 
    android:textColor="@color/edtTextColor" 
    android:background="@color/bgEdtColor" 
    /> 
1

आप उपयोगकर्ता पाठ TextView में प्रवेश करने की अनुमति देने के लिए नहीं करना चाहते हैं: बस पृष्ठभूमि रंग EditText में निर्धारित किया है। इस उद्देश्य के लिए आप EditText भी जोड़ सकते हैं। इसके लिए यहां एक नमूना कोड है।

यदि निर्दिष्ट पंक्तियों से अधिक टेक्स्ट है तो यह स्वचालित रूप से स्क्रॉलबार दिखाएगा।

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="textMultiLine" 
    android:lines="8" 
    android:maxLines="10" 
    android:minLines="6" 
    android:scrollbars="vertical" /> 

संपादित करें: textView लिए नीचे दिए गए जोड़ा जा रहा है गुण यह एक textArea कि संपादन योग्य नहीं होगा होगा।

android:lines="8" 
android:maxLines="10" 
android:minLines="6" // optional 
संबंधित मुद्दे