සකස් කර ගන්නේ කෙසේද කියා TextViewජාවා තුල හා XML සැකැස්ම භාවිතා නොකර (තද හෝ ඇල අකුරු) ශෛලිය?
වෙනත් වචන වලින් කිවහොත්, මට android:textStyleජාවා සමඟ ලිවිය යුතුය.
Answers:
textView.setTypeface(null, Typeface.BOLD_ITALIC);
textView.setTypeface(null, Typeface.BOLD);
textView.setTypeface(null, Typeface.ITALIC);
textView.setTypeface(null, Typeface.NORMAL);
පෙර යතුරුලියනය තබා ගැනීමට
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC)
textView.setTypeface(textView.getTypeface(), Typeface.NORMAL);a වෙතින් තද හෝ ඇල අකුරු ඉවත් නොකරනු ඇත TextView. ඒ සඳහා ඔබට භාවිතා කිරීමට අවශ්ය වනු ඇත textView.setTypeface(null, Typeface.NORMAL);.
textView.setTypeface(Typeface.create(textView.getTypeface(), Typeface.NORMAL), Typeface.NORMAL);
TextViewතද හෝ ඇල අකුරු සඳහා මෙය සකසන්න
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);
tv.setTypeface(Typeface.create(tv.getTypeface(), Typeface.NORMAL));
tv.setTypeface(null, Typeface.BOLD);නොකරනු ඇත (පවතින යතුරු පුවරුවේ ශෛලිය ඉවත් කරන්න)?
ඔබට ක්රමලේඛනය මඟින් මෙය කළ හැකිය setTypeface():
textView.setTypeface(null, Typeface.NORMAL); // for Normal Text
textView.setTypeface(null, Typeface.BOLD); // for Bold only
textView.setTypeface(null, Typeface.ITALIC); // for Italic
textView.setTypeface(null, Typeface.BOLD_ITALIC); // for Bold and Italic
ඔබට කෙලින්ම XML ගොනුවේ මෙසේ සැකසිය හැකිය <TextView />:
android:textStyle="normal"
android:textStyle="normal|bold"
android:textStyle="normal|italic"
android:textStyle="bold"
android:textStyle="bold|italic"
with in Java and without using XMLමාර්ගය වන විට එය අන් අයටද උපකාරී වනු ඇත.
ඔබට විකල්ප දෙකක් තිබේ:
විකල්ප 1 (තද, ඇල අකුරු සහ යටි ඉරි සඳහා පමණක් ක්රියා කරයි):
String s = "<b>Bolded text</b>, <i>italic text</i>, even <u>underlined</u>!"
TextView tv = (TextView)findViewById(R.id.THE_TEXTVIEW_ID);
tv.setText(Html.fromHtml(s));
විකල්ප 2:
ස්පැනබල් භාවිතා කරන්න ; එය වඩාත් සංකීර්ණ වේ, නමුත් ඔබට පෙළ ගුණාංග ගතිකව වෙනස් කළ හැකිය (තද / ඇල අකුරු පමණක් නොව වර්ණද).
typeFaceඔබ මුළු පෙළ සඳහා තනි ශෛලිය සැකසිය හැක.
setTypeface()ක්රමවේදය භාවිතයෙන් ඔබට ක්රමලේඛිකව කළ හැකිය :
පෙරනිමි යතුරු පුවරුව සඳහා කේතය පහත දැක්වේ
textView.setTypeface(null, Typeface.NORMAL); // for Normal Text
textView.setTypeface(null, Typeface.BOLD); // for Bold only
textView.setTypeface(null, Typeface.ITALIC); // for Italic
textView.setTypeface(null, Typeface.BOLD_ITALIC); // for Bold and Italic
ඔබට අභිරුචි යතුරු පුවරුව සැකසීමට අවශ්ය නම් :
textView.setTypeface(textView.getTypeface(), Typeface.NORMAL); // for Normal Text
textView.setTypeface(textView.getTypeface(), Typeface.BOLD); // for Bold only
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC); // for Italic
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC); // for Bold and Italic
ඔබට කෙලින්ම මේ ආකාරයට XML ගොනුවේ සැකසිය හැකිය <TextView />:
android:textStyle="normal"
android:textStyle="normal|bold"
android:textStyle="normal|italic"
android:textStyle="bold"
android:textStyle="bold|italic"
නැතහොත් ඔබට ඔබේ අකුරු අකුරු (වත්කම් වලින්) සැකසිය හැකිය. වැඩි විස්තර සඳහා සබැඳිය බලන්න
TextView text = (TextView)findViewById(R.id.THE_TEXTVIEW_ID);
දැන් textviewගුණාංග සකසන්න ..
text.setTypeface(null, Typeface.BOLD); //-- for only bold the text
text.setTypeface(null, Typeface.BOLD_ITALIC); //-- for bold & italic the text
text.setTypeface(null, Typeface.ITALIC); // -- for italic the text
වනු ඇත
yourTextView.setTypeface(null,Typeface.DEFAULT_BOLD);
සහ ඇල අකුරු ප්රතිස්ථාපනය Typeface.DEFAULT_BOLDසමඟ විය යුතුය Typeface.DEFAULT_ITALC.
එය ක්රියාත්මක වන ආකාරය මට දන්වන්න.
textView.setTypeface(Typeface tf, int style);ශෛලීය දේපල සැකසීමට භාවිතා කරන්න TextView. වැඩි විස්තර සඳහා සංවර්ධක ප්රලේඛනය බලන්න .
මේක උත්සාහ කරන්න:
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);
මේක උත්සාහ කරන්න:
TextView textview = (TextView)findViewById(R.id.textview_idname);
textview.setTypeface(null,Typeface.BOLD);
මෙය කිරීමට සම්මත ක්රමය වන්නේ අභිරුචි මෝස්තර භාවිතා කිරීමයි. උදා-
දී styles.xmlපහත සඳහන් එක් කරන්න.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyApp.TextAppearance.LoginText">
<item name="android:textStyle">bold|italic</item>
</style>
මෙම ශෛලිය TextViewපහත පරිදි ඔබේ ආලේප කරන්න.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyApp.TextAppearance.LoginText" />
ඔබට කළ හැකි එක් ක්රමයක් නම්:
myTextView.setTypeface(null, Typeface.ITALIC);
myTextView.setTypeface(null, Typeface.BOLD_ITALIC);
myTextView.setTypeface(null, Typeface.BOLD);
myTextView.setTypeface(null, Typeface.NORMAL);
ඔබට පෙර යතුරු ලියනය තබා ගැනීමට අවශ්ය නම් තවත් විකල්පයක් නම් කලින් අයදුම් කළ දේ නැති කර ගැනීමට අවශ්ය නොවන්නේ නම්:
myTextView.setTypeface(textView.getTypeface(), Typeface.NORMAL);
myTextView.setTypeface(textView.getTypeface(), Typeface.BOLD);
myTextView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
myTextView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);
ඔබට මේ ආකාරයට උත්සාහ කළ හැකිය:
<string name="title"><u><b><i>Your Text</i></b></u></string>
විලාසිතාව තෝරා ගැනීමේ නිර්ණායක මත පදනම්ව ඔබට කළ හැකි පහසුම ක්රමය:
String pre = "", post = "";
if(isBold){
pre += "<b>"; post += "</b>";
}
if(isItalic){
pre += "<i>"; post += "</i>";
}
if(isUnderline){
pre += "<u>"; post += "</u>";
}
textView.setText(Html.fromHtml(pre + editText.getText().toString()+ post));
// you can also use it with EidtText
editText.setText(Html.fromHtml(pre + editText.getText().toString()+ post));
මට අභිරුචි අකුරු භාවිතා කිරීමට අවශ්ය බැවින් පිළිතුරු කිහිපයක් පමණක් ඒකාබද්ධ කිරීම මට වැඩ කරයි. නිසැකවම මා layout.xmlවැනි සැකසුම් android:textStlyle="italic"AOS විසින් නොසලකා හරින ලදි. එබැවින් අවසාන වශයෙන් මට පහත පරිදි කිරීමට සිදු විය: strings.xmlඉලක්කගත නූලෙහි මෙසේ ප්රකාශ විය:
<string name="txt_sign"><i>The information blah blah ...</i></string>
ඊට අමතරව කේතයෙන්:
TextView textSign = (TextView) findViewById(R.id.txt_sign);
FontHelper.setSomeCustomFont(textSign);
textSign.setTypeface(textSign.getTypeface(), Typeface.ITALIC);
මම Spannableවිකල්පය උත්සාහ කළේ නැත (එය වැඩ කළ යුතු යැයි මම සිතමි) නමුත්
textSign.setText(Html.fromHtml(getString(R.string.txt_sign)))
කිසිදු බලපෑමක් ඇති කළේ නැත. ද මම ඉවත් කරනවා නම් italic tagවලින් strings.xmlහැර යන setTypeface()සියල්ල තනිව එය එක්කෝ කිසිදු බලපෑමක් ඇති කොට ඇත. උපක්රමශීලී ඇන්ඩ්රොයිඩ් ...
මෙහි විස්තර කර ඇති පරිදි ඇන්ඩ්රොයිඩ් සංවර්ධකයින්ගේ සංගීත සම්පත් ඔබේ මෝස්තරගත පෙළ සම්පතෙහි පරාමිතීන් භාවිතා කිරීමට අවශ්ය නම්, ඔබට ආරම්භක වරහන් වලින් ගැලවිය යුතුය
<resources>
<string name="welcome_messages">Hello, %1$s! You have <b>%2$d new messages</b>.</string>
</resources>
ආකෘතිය අමතන්න HTML (string)
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
CharSequence styledText = Html.fromHtml(text);
මගේ තත්වයේදි:
1 - පෙළ සකසන්න
2 - යතුරු ලියනය සකසන්න
holder.title.setText(item.nome);
holder.title.setTypeface(null, Typeface.BOLD);
AndroidX සමඟ සරල කළ ටැග් භාවිතා කරන අතරතුර HtmlCompat.fromHtml () භාවිතා කිරීම සලකා බලන්න
String s = "<b>Bolded text</b>, <i>italic text</i>, even <u>underlined</u>!"
TextView tv = (TextView)findViewById(R.id.THE_TEXTVIEW_ID);
tv.setText(HtmlCompat.fromHtml(s, FROM_HTML_MODE_LEGACY));
පහත දැක්වෙන උදාහරණය භාවිතා කර ඔබට විවිධ යතුරුලියනය සැකසිය හැකිය -
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
textView.setTypeface(textView.getTypeface(), Typeface.ITALIC);
textView.setTypeface(textView.getTypeface(), Typeface.BOLD_ITALIC);
නැතහොත් ඔබට වෙනත් අකුරු වර්ගයක් සහ එහි යතුරු පුවරුව සැකසීමට අවශ්ය නම්. වත්කම් හෝ අමු ෆෝල්ඩරයට එය එකතු කර එය මෙන් භාවිතා කරන්න
Typeface face= Typeface.createFromAsset(getAssets(), "font/font.ttf");
tv1.setTypeface(face);
Typeface face1= Typeface.createFromAsset(getAssets(), "font/font1.ttf");
tv2.setTypeface(face1);
හොඳම ක්රමය එය අර්ථ දැක්වීමයි styles.xml
<style name="common_txt_style_heading" parent="android:style/Widget.TextView">
<item name="android:textSize">@dimen/common_txtsize_heading</item>
<item name="android:textColor">@color/color_black</item>
<item name="android:textStyle">bold|italic</item>
</style>
එය යාවත්කාලීන කරන්න TextView
<TextView
android:id="@+id/txt_userprofile"
style="@style/common_txt_style_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/margin_small"
android:text="@string/some_heading" />
1) ඔබට එය TypeFace සමඟ සැකසිය හැකිය. 2) ඔබට කෙලින්ම strings.xml භාවිතා කළ හැකිය (ඔබේ වටිනාකම් ෆෝල්ඩරයේ) 3) ඔබට String myNewString = "මෙය මගේ තද අකුරු පා text ය මෙය මගේ ඇල අකුරු වේ මෙය මගේ යටි ඉරි ඇඳ ඇති නූලයි