आप XML फ़ाइल में किसी टेक्स्ट को कैसे रेखांकित करते हैं? मुझे इसमें कोई विकल्प नहीं मिल रहा है textStyle
।
textView.setText(Html.fromHtml("<u>"+"testest"+"</u>"));
आप XML फ़ाइल में किसी टेक्स्ट को कैसे रेखांकित करते हैं? मुझे इसमें कोई विकल्प नहीं मिल रहा है textStyle
।
textView.setText(Html.fromHtml("<u>"+"testest"+"</u>"));
जवाबों:
यदि आप एक स्ट्रिंग संसाधन xml फ़ाइल (HTML टैग का समर्थन करता है) का उपयोग कर रहे हैं, तो इसका उपयोग करके किया जा सकता है <b> </b>
, <i> </i>
और <u> </u>
।
<resources>
<string name="your_string_here">
This is an <u>underline</u>.
</string>
</resources>
यदि आप कोड के उपयोग से कुछ रेखांकित करना चाहते हैं:
TextView tv = (TextView) view.findViewById(R.id.tv);
SpannableString content = new SpannableString("Content");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
tv.setText(content);
उम्मीद है की यह मदद करेगा
<u>
टैग के माध्यम से अंतर्निहित काम नहीं करता है, उदाहरण के लिए कभी-कभी यदि आप एक कस्टम फ़ॉन्ट का उपयोग कर रहे हैं। हालांकि, प्रोग्राम द्वारा अंतर्निहित UnderlineSpan
वास्तव में मुझ पर कभी विफल नहीं हुआ है, इसलिए मैं इसे सबसे विश्वसनीय समाधान के रूप में सुझाऊंगा।
<u>
और <\u>
XML में, और यह पर्याप्त है।
इसे इस्तेमाल करो:
TextView txt = (TextView) findViewById(R.id.Textview1);
txt.setPaintFlags(txt.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
UnderlineSpan
।
<resource>
<string name="your_string_here">This is an <u>underline</u>.</string>
</resources>
अगर यह काम नहीं करता है
<resource>
<string name="your_string_here">This is an <u>underline</u>.</string>
क्योंकि "<" कुछ समय में एक कीवर्ड हो सकता है।
और प्रदर्शित करने के लिए
TextView textView = (TextView) view.findViewById(R.id.textview);
textView.setText(Html.fromHtml(getString(R.string.your_string_here)));
सबसे पहले, String.xml फ़ाइल पर जाएं
आप इसमें किसी भी HTML विशेषताओं को जोड़ सकते हैं, जैसे इटैलिक या बोल्ड या रेखांकित करना।
<resources>
<string name="your_string_here">This is an <u>underline</u>.</string>
</resources>
इसे करने का एक और तरीका है, TextView का विस्तार करने वाला एक कस्टम घटक बनाना। यह उन मामलों के लिए अच्छा है जहाँ आपको कई रेखांकित पाठ दृश्य चाहिए।
यहाँ घटक के लिए कोड है:
package com.myapp.components;
import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.util.AttributeSet;
public class LinkTextView extends AppCompatTextView {
public LinkTextView(Context context) {
this(context, null);
}
public LinkTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void setText(CharSequence text, BufferType type) {
SpannableString content = new SpannableString(text);
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
super.setText(content, type);
}
}
और xml में इसका उपयोग कैसे करें:
<com.myapp.components.LinkTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!" />
भाविन उत्तर को पूरा करने के लिए। छूट के लिए, अंडरलाइन या पुनर्निर्देशन को जोड़ने के लिए।
((TextView) findViewById(R.id.tv_cgu)).setText(Html.fromHtml(getString(R.string.upload_poi_CGU)));
<string name="upload_poi_CGU"><![CDATA[ J\'accepte les <a href="">conditions générales</a>]]></string>
और आप यहां संगत टैग जान सकते हैं: http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
आप नीचे दिए गए मार्कअप का उपयोग कर सकते हैं, लेकिन ध्यान दें कि यदि आप अंडरलाइन प्रभाव सेट करते textAllCaps
हैं true
तो हटा दिया जाएगा।
<resource>
<string name="my_string_value">I am <u>underlined</u>.</string>
</resources>
ध्यान दें
एक स्ट्रिंग (login_change_settings) के साथ textAllCaps का उपयोग करना जिसमें मार्कअप होता है; कैपस रूपांतरण द्वारा मार्कअप को हटा दिया जाएगा
TextAllCaps टेक्स्ट ट्रांसफ़ॉर्मेशन CharSequence पर कॉलिंग स्ट्रिंग को समाप्त कर देगा, जिसमें किसी भी मार्कअप को हटाने का शुद्ध प्रभाव है। यह जाँच मार्कअप वाले तार के usages की तलाश करती है जो textAllCaps = true को निर्दिष्ट करते हैं।
Android TextView में रेखांकित पाठ को प्राप्त करने के विभिन्न तरीके हैं।
1. <u>This is my underlined text</u>
या
I just want to underline <u>this</u> word
2. आप एक ही प्रोग्राम कर सकते हैं।
`textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);`
3. यह एक SpannableString बनाकर और फिर इसे TextView टेक्स्ट प्रॉपर्टी के रूप में सेट करके किया जा सकता है
SpannableString text = new SpannableString("Voglio sottolineare solo questa parola");
text.setSpan(new UnderlineSpan(), 25, 6, 0);
textView.setText(text);
मैंने नीचे विधि का उपयोग किया, यह मेरे लिए काम करता है। नीचे बटन के लिए उदाहरण है, लेकिन हम TextView में भी उपयोग कर सकते हैं।
Button btnClickMe = (Button) findViewById(R.id.btn_click_me);
btnClickMe.setPaintFlags(btnClickMe.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
यदि आप पाठ स्ट्रिंग की तुलना करना चाहते हैं या पाठ गतिशील रूप से बदल जाएगा तो आप बाधा लेआउट में एक दृश्य बना सकते हैं यह इस तरह पाठ की लंबाई के अनुसार समायोजित करेगा
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_Previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:text="Last Month Rankings"
android:textColor="@color/colorBlue"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View
android:layout_width="0dp"
android:layout_height="0.7dp"
android:background="@color/colorBlue"
app:layout_constraintEnd_toEndOf="@+id/txt_Previous"
app:layout_constraintStart_toStartOf="@+id/txt_Previous"
app:layout_constraintBottom_toBottomOf="@id/txt_Previous"/>
</android.support.constraint.ConstraintLayout>
public void setUnderLineText(TextView tv, String textToUnderLine) {
String tvt = tv.getText().toString();
int ofe = tvt.indexOf(textToUnderLine, 0);
UnderlineSpan underlineSpan = new UnderlineSpan();
SpannableString wordToSpan = new SpannableString(tv.getText());
for (int ofs = 0; ofs < tvt.length() && ofe != -1; ofs = ofe + 1) {
ofe = tvt.indexOf(textToUnderLine, ofs);
if (ofe == -1)
break;
else {
wordToSpan.setSpan(underlineSpan, ofe, ofe + textToUnderLine.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(wordToSpan, TextView.BufferType.SPANNABLE);
}
}
}
TextView tv = findViewById(R.id.tv);
tv.setText("some text");
setUnderLineText(tv, "some");
इसके अलावा EditText, Button, Checkbox जैसे TextView childs का समर्थन करें
अगर तुम चाहते हो
- क्लिक करने योग्य अंडरलाइन टेक्स्ट?
- TextView के कई भागों को रेखांकित करें?
style="text-decoration: underline;"