久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

EditText - 更改文本的背景顏色(只有文本 - 不是整

EditText - change background color of text (and only text - not the whole view)(EditText - 更改文本的背景顏色(只有文本 - 不是整個(gè)視圖))
本文介紹了EditText - 更改文本的背景顏色(只有文本 - 不是整個(gè)視圖)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

當(dāng)用戶在 EditText 中輸入信息,并移動(dòng)到下一個(gè) EditText 時(shí),信息會(huì)高亮顯示,如下所示:

When a user enters information in an EditText, and moves to the next EditText, the information is highlighted as shown below:

代碼:

edittext.setOnFocusChangeListener(new OnFocusChangeListener() {

@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (hasFocus) {
        v.setBackgroundColor(Color.WHITE);
        ((EditText) v).setTextColor(Color.BLACK);
    } else {

        //v.setBackgroundColor(Color.LTGRAY); //also works like this
        ((EditText) v).setBackgroundColor(Color.LTGRAY);
        ((EditText) v).setTextColor(Color.BLACK);
    }

   }
});

onCreate 方法中調(diào)用如下:

Which is called in the onCreate method like this:

edittext = (EditText) findViewById(R.id.editText1);

但是,如果背景顏色只應(yīng)用于文本本身而不是視圖,那就更好了,就像這樣(來自 gmail 應(yīng)用程序):

However, It would be much better if the background color only applied to the text itself, rather than the view, like this (from the gmail app):

是否有人對(duì)如何將背景顏色僅應(yīng)用于文本(而不是整個(gè) EditText 視圖)有任何建議?

Does anybody have any suggestions on how to apply the background color to the text only (not the whole EditText view) as above?

謝謝.

推薦答案

您可以使用 BackgroundColorSpan 來實(shí)現(xiàn)您想要的.您可以在此處找到更多信息:

You can achieve what you want by using a BackgroundColorSpan. You can find more information here:

http://developer.android.com/reference/android/text/style/BackgroundColorSpan.html

要使用 span,您需要構(gòu)建一個(gè) SpannableString,您可以使用 SpannableStringBuilder:

To use spans you need to build a SpannableString which you can do using a SpannableStringBuilder:

http://developer.android.com/reference/android/text/SpannableStringBuilder.html

這篇關(guān)于EditText - 更改文本的背景顏色(只有文本 - 不是整個(gè)視圖)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 精品二三区 | a黄视频 | 国产高清在线精品一区二区三区 | 黄色大片免费网站 | 久久亚洲视频 | 一区二区三区国产 | 免费高清av | 日本中文字幕在线视频 | 国产1区2区在线观看 | 亚洲国产aⅴ成人精品无吗 欧美激情欧美激情在线五月 | 久久久噜噜噜久久中文字幕色伊伊 | 久久久久久久av | 成人网av| 九九精品久久久 | 蜜月va乱码一区二区三区 | 久久婷婷麻豆国产91天堂 | www国产成人 | 精品国产一区二区三区久久 | 亚洲资源站 | 成人久久网 | 国产精品99久久久久久久久久久久 | 欧美大片在线观看 | 久久一二| 国产亚洲精品精品国产亚洲综合 | 99re6在线视频 | 香蕉久久a毛片 | 91久久综合 | 国产精品不卡视频 | 黄网站免费在线观看 | 国产精品www| 久久久久久久久久影视 | 午夜亚洲 | 真人女人一级毛片免费播放 | 国产亚洲成av人在线观看导航 | 99久久久久久久 | 性视频一区 | 97免费在线观看视频 | 欧美一级淫片免费视频黄 | 中文天堂在线一区 | 日本国产欧美 | 在线一区视频 |