本文介紹了Android EditText + 設(shè)置一些顏色的單詞的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我根據(jù)從數(shù)據(jù)庫中提取的內(nèi)容動態(tài)創(chuàng)建 EditText 框.
I create EditText boxes dynamically, depending on what is pulled back from the database.
即.
final EditText textV = new EditText(this);
textV.setText(monEntry);
有沒有在不使用 subString() 的情況下將 EditText 中的一些文本設(shè)置為一種顏色和另一種顏色?如果有人可以提供幫助,非常感謝!
Is there anyway to set some of the text in the EditText to one colour and another bit to another without using a subString()? Thanks alot if anybody can help!
推薦答案
是的,如果您使用 SpannableString,您可以在文本的不同位置使用不同的顏色.示例:
Yes, you can have different colors in different places of the text if you are using SpannableString. Example:
SpannableString text = new SpannableString("Lorem ipsum dolor sit amet");
final EditText textV = new EditText(this);
// make "Lorem" (characters 0 to 5) red
textV.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);
textV.setText(text, BufferType.SPANNABLE);
或者你可以使用下面的html代碼::
or you can use html code as below::
textV.setText(Html.fromHtml(html text having 1 in red 2 in green and so on));
這里有一個更完整的例子.
SpannableString
這篇關(guān)于Android EditText + 設(shè)置一些顏色的單詞的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!