英文:
How to italic a word in sentence on Android studio?
问题
I'm new at developing an Android app. I wanted to make some of the words into italic, but it's not working properly.
Can you tell me is it possible to make a word in sentence into italic? If it's possible tell me how to make it italic?
我是新手开发Android应用程序。我想将一些单词变成斜体,但它不起作用。
你能告诉我在句子中将单词变成斜体是否可能吗?如果可能,请告诉我如何使它变成斜体?
I made a glossary with a ListView, the sentence I made it in an ArrayList like this
我用ListView制作了一个词汇表,我将句子制作成了一个ArrayList,像这样
a.add("Acuminatus" + "Type of leaf");
a.add("Acuminatus" + "叶子的类型");
How to italicize the word "Acuminatus"? I have tried to add it like this
如何使单词“Acuminatus”变成斜体?我尝试添加如下
"<i>Acuminatus</i>"
但仍然不起作用
More of the code
更多的代码
private List<String> populateA() {
List<String> a = new ArrayList<String>();
a.add("Acuminatus" + "\n\nType of leaf");
.....
return a;
}
英文:
I'm new at developing an Android app. I wanted to make some of the words into italic, but it's not working properly.
Can you tell me is it possible to make a word in sentence into italic? If it's possible tell me how to make it italic?
I made a glosarium with listview, the sentence I made it on array list like this
a.add("Acuminatus"+"Type of leaf");
How to italic the word "Acuminatus" I have tried to add like
"0 Acuminatus"
Or
"<i>Acumunatus</i>"
But its still not working
More the code
Private List<String> populateA() {
List<String> a=new ArrayList<String>();
a.add("Acuminatus"+"\n \n Type of leaf");
.....
Return a;
}
答案1
得分: 1
使用以下方法来显示:
public static Spanned fromHtml(String html) {
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html, FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
调用方式如下:
textview.setText(fromHtml("<i>Acumunatus</i> Type of leaf"))
英文:
Use the below method where you are going to display:
public static Spanned fromHtml(String html) {
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html, FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
Calling Like:
textview.setText(fromHtml("<i>Acumunatus</i> Type of leaf"))
答案2
得分: 0
你可以使用SpannableString
与StyleSpan
类型的Span。调用setSpan()
方法,该方法接受要样式化的文本的索引。
SpannableString output = new SpannableString("Acuminatus" + " 叶的类型");
output.setSpan(new StyleSpan(Typeface.ITALIC), 0, 11, 0);
textview.setText(output);
英文:
You can use SpannableString
with a Span of type StyleSpan
.. Call setSpan()
that takes the indices of the text that you want to style
SpannableString output = new SpannableString("Acuminatus" + " Type of leaf");
output.setSpan(new StyleSpan(Typeface.ITALIC), 0, 11, 0);
textview.setText(output);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论