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

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

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

問題描述

限時送ChatGPT賬號..

當用戶在 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 方法中調用如下:

Which is called in the onCreate method like this:

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

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

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

是否有人對如何將背景顏色僅應用于文本(而不是整個 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,您需要構建一個 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

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

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

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
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(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 久久国产精品一区二区三区 | 91精品国产自产精品男人的天堂 | 三区四区在线观看 | 在线免费91| 欧美13videosex性极品 | 日本成人免费网站 | 免费成人高清在线视频 | 久久国内 | 午夜成人免费视频 | 国产精品三级 | 久在线| 亚洲电影一区二区三区 | 国产亚洲精品精品国产亚洲综合 | 91麻豆精品国产91久久久更新资源速度超快 | 亚洲精品久久久久久久久久久 | 91av在线不卡 | 欧美在线天堂 | 免费视频99 | 影音先锋男 | 国产精品久久久久久久久 | 久久久久久久av | 一区二区三区四区在线播放 | 成人精品视频在线观看 | 国产中文字幕av | 一区二区三区福利视频 | 亚洲不卡在线观看 | 久久久蜜桃一区二区人 | 一区二区三区四区不卡视频 | 亚洲最新在线视频 | 女朋友的闺蜜3韩国三级 | 精品一区二区三区入口 | 91观看| 一级片av | 国产精品美女 | 国产成人精品免高潮在线观看 | 亚洲精品高清视频 | 99re99| 男女视频在线观看网站 | 色接久久 | 日韩精品一区二区三区在线 | 99色综合|