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

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

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

問題描述

限時送ChatGPT賬號..

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

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):

是否有人對如何將背景顏色僅應(yīng)用于文本(而不是整個 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 來實現(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)建一個 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 - 更改文本的背景顏色(只有文本 - 不是整個視圖)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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問題)
主站蜘蛛池模板: 91精品久久久久久粉嫩 | 亚洲日本视频 | www.99精品| 黄色片在线看 | 成人免费毛片嘿嘿连载视频 | 看毛片网站 | 日本丰满少妇裸体自慰 | 成人午夜毛片 | 三级黄色片网站 | aa一级片 | 久久在线免费观看 | 国产91清纯白嫩初高中在线观看 | 蜜桃精品一区二区三区 | 日日操视频| a级片在线免费观看 | 亚洲成人精品在线 | 国产一级黄色大片 | 国产永久在线 | 97福利视频 | 亚洲国产日韩在线 | 久久精品国产精品 | 国产精品一区久久 | 黄视频免费看网站 | 国产中文字幕在线观看 | av基地网 | 亚洲国产成人av | 国产三级黄色片 | 久久精品在线 | 欧美日韩国 | 中文字幕在线免费观看 | 在线a| 一级片免费视频 | 国产精品主播一区二区 | 成人毛片在线观看 | 国产成人区 | 9.1成人看片免费版 国产草草影院 | 久久福利网| 精品视频在线观看免费 | 青青草国产在线视频 | 中文字幕在线免费观看视频 | 亚洲黄色免费 |