EditText設定文字背景實用需求

2021-08-26 04:52:18 字數 831 閱讀 7943

之前想做這樣乙個效果,

如圖:[img]

之前的code:

et = (edittext) findviewbyid(r.id.et);

string text = ""+"123456789"+"";

et.settext(html.fromhtml(text));

這個是實現不了的.

後來發現editview的selectall()屬性.

該屬性意味選中當前所有文字。

修改之後:

et = (edittext) findviewbyid(r.id.et);

string text = "123456456";

et.settext(text);

et.selectall();//設定全部選中

et.sethighlightcolor(color.blue);//設定選中背景色

這樣,文字背景色設定ok.

效果:[img]

如果還要設定文字字型顏色,如上如一樣。

可以這樣去做:

et = (edittext) findviewbyid(r.id.et);

string text = "123456456";

et.settext(html.fromhtml(""+text+""));

et.selectall();//設定全部選中

et.sethighlightcolor(color.blue);//設定選中背景色

效果:[img]

編輯文字(EditText)

先看一下它的基本屬性 2.xml檔案 android layout width match parent android layout height match parent android orientation vertical android padding 5dp android layou...

修改EditText背景和游標

安卓原生的edittext樣式不太好看 游標和背景 不同的專案都需要定製。2 styles.xml中修改coloraccent對應顏色即可。color colorprimarydark color coloraccent 效果圖 次選方案 如果不能修改主題,要單獨定製某個edittext的游標和背景...

手機開發 EditText設定更多文字為省略號

在textiew中可以通過設定textview的屬性android maxems和android ellipseize來使過多的文字顯示為省略號,在edittext中設定只這兩個屬性則不行,android預設只有在文字不可編輯的狀態下才可以顯示這些效果,但是edittext重寫了這個屬性,使得文字預...